Runtime.exec() paramater "String[] envp"

Hi,
envp - array of strings, each element of which has environment variable settings in the format name=value, or null if the subprocess should inherit the environment of the current process.
That's a formal definition of Runtime.exec()'s function argument
but what exactly it is responsible for?
Could you give me any usage examples?
Thanks!

It's responsible for setting the environment variable.
String[] envvars = { "temp=C:\TEMP" };

Similar Messages

  • Runtime.exec using extended envp

    Hello,
    I would like to call Runtime.exec(String[], String[]), using the already existing environment variables with some modifications. Anyone have a tip how to accomplish this?

    ugly hack, yes but it should work:
    in pseudocode:
    Process p = Runtime.exec(my Shell's name);
    p.getOutputStream().write("setenv stuff"); // do this to modify your enviornment
    p.getOutputStream().write("my executable");
    That would allow you to modify the enviornment of your child process.

  • Runtime.exec  problems

    Hi
    I would like to open a chm file from my "help" menu.
    I got two problem related to that:
    1.The first time the menu is clicked i start the process and the help is opened on top of my application frame.
    but - the second time It is opened - the only wat to recognize i sthe process is still active is to call exitValue (if it get an exception - process is still active) but - how can i make the frame on top of my application frame( the current active frame)
    2.when the application is closed the help application does not "die" with the rest of the application.
    I will be happy to get some ideas of how can i control it.
    this is my code:
    Runtime runtime=  Runtime.getRuntime();
            try {
                if(process==null){
                     process=runtime.exec(new String[] {"cmd.exe","/c" , helpLink});
                else{
                    try {
                        process.exitValue();
                        process = runtime.exec(new String[]{"cmd.exe", "/c", helpLink});
                        if (log.isDebugEnabled())
                            log.debug("process finish working");
                    } catch (IllegalThreadStateException e1) {
                        if (log.isDebugEnabled())
                            log.debug("process still working");
            } catch (IOException e1) {
                if (log.isErrorEnabled()){
                    log.error("could not open help file"+ helpLink);
                    log.error("exception:",e1);
                WorkingAreaManager.getWorkingAreaManagerInstance().displayErrorMessage(COULD_OPEN_HELP);
            }thanks,Liat

    1.The first time the menu is clicked i start the
    process and the help is opened on top of my
    application frame.
    but - the second time It is opened - the only wat to
    recognize i sthe process is still active is to call
    exitValue (if it get an exception - process is still
    active) but - how can i make the frame on top of my
    application frame( the current active frame)Sorry I don't know the answer to that. What happens if you invoke it a second time... does it bring up a completely new frame?
    2.when the application is closed the help application
    does not "die" with the rest of the application.
    I will be happy to get some ideas of how can i
    control it.process.destroy()?

  • Runtime#exec() from within a J2EE application

    I've got a batch processing task running on a timer as part of my J2EE application on WebLogic 8.1 and I'm experiencing problems with invoking Runtime#exec().
    To be more accurate, this is what I'm trying to do:
    * Moves a file in the filesystem using native shell commands.
    * @param src The file to move.
    * @param dst The destination file.
    public void move(String src, String dst) {
        Runtime runtime = Runtime.getRuntime();
        Process p = runtime.exec(new String[] { "mv", "-f", src, dst });
    }Now, this piece of code works perfectly when run manually ("java Move foo.txt bar.txt") but when it's run within the J2EE application -- as the same user as in the manual case -- the file's won't get moved anywhere.
    I suppose it's a permission/policy issue. If that's the case, how should I edit the policy file?
    I already tried to add the following lines to weblogic.policy:
    grant codeBase "file:${user.domain}/myServer/.internal/-" {
      permission java.security.AllPermission;
    grant codeBase "file:${user.domain}/myServer/.wlnotdelete/-" {
      permission java.security.AllPermission;
    };...but that didn't seem to help at all.

    Ok. I managed to solve this one by myself. The solution was to read the "stdout" and "stderr" streams from the process.
    Any idea why reading the streams helped?

  • Parameter  to shell script using Runtime.exec(string)

    Hi all, ( Speciall hi to dheeraj tak )
    Briefly : How do i pass an arguement to a non - java executible being called using Runtime.exec.
    In detail : i am using Runtime.exec to call a shell script : The code is as follows:
    String callAndArgs[] = {"/home/tom/jakarta-tomcat-4.1.24/webapps/dash/script.sh"};
    try {
    Runtime rt = Runtime.getRuntime();
    Process child = rt.exec(callAndArgs);
    This works properly & calls the shell script which in turn invokes some other executible (c file).
    $HOME/midi/test/build/bin/<C-EXECUTIBLE>
    Here i am specifying the name (say hello.exe ) . So far so good.
    I want to make this happen dynamiclaly. so i need to pass the name of the executible as a parameter to the script.
    To pass a parameter i hav to change the string to :-
    String callAndArgs[] = {"/home/tom/jakarta-tomcat-4.1.24/webapps/dash/script.sh <C-EXECUTIBLE HERE>"};
    and the script to
    $HOME/midi/test/build/bin/$1 --- where $1 refers to argument 1. (C-EXECUTIBLE AGAIN).
    This is giving an IO - Execption. Plz help
    Code will be very helpful.
    Thanx in advance

    some 1 plz tell me the difference :-
    This is the documentation of Runtime.exec that i found :-
    1> exec
    public Process exec(String command) throws IOException
    Executes the specified string command in a separate process.
    The command argument is parsed into tokens and then executed as a command in a separate process. This method has exactly the same effect as exec(command, null).
    Parameters:
    command - a specified system command
    Complete refernce says : Process (String progName) ----- Executes a program specified by programname as a seperate process.
    2> exec
    public Process exec(String cmdarray[]) throws IOException
    Executes the specified command and arguments in a separate process.
    The command specified by the tokens in cmdarray is executed as a command in a separate process. This has exactly the same effect as exec(cmdarray, null).
    Parameters:
    cmdarray - array containing the command to call and its arguments.
    Complete reference says : Process exec(String comLineArray[]) ---- Executes the command line specified bythe string in comLineArray as a seperate process.
    This means that there is provision 4 command line arguments...
    how do u use it then????????????????????????????

  • PB with Runtime.exec(String);

    hi,
    in using Runtime.exec(string);
    he say :
    the method exec(java.lang.String) from the type java.long.Runtime is not static.
    Someone can help me please.

    use:
    Runtime.getRuntime().exec(String);

  • Runtime.exec with spaces not working EVEN using String[]!!

    Hi everyone,
    I need to start the rmi registry from some code,and i need to pass it the classpath of two jars when initialising it. My problem is that the paths I set aren't taken when they contain a space.
    Here's the code:
    <code>
    String rmiRegistryCommandLine[] = new String[] {
    + System.getProperty("java.home")
    + "\\bin\\rmiregistry.exe\"",
    "-J-Djava.class.path=\""+System.getProperty("user.dir")+"\\MyJar.jar\"",
    "1099"};
                                            Runtime.getRuntime().exec(rmiRegistryCommandLine);
    </code>
    I know that Runtime.exec(String) tokenizes the input, which is why I'm not using it, but Runtime.exec(String[]) isn't supposed to tokenize the input. System.getProperty("user.dir") can contain a space, so I put quotes around that, but I need the -J-Djava.class.path in the same string. I tried breaking it up into two more separate strings but it didn't even run for normal non-space paths then. I am sure that if the whole -J-Dblah....upto MyJar.jar was in quotes then it would work, but I need the classpath in quotes separately as it could contain a space.
    Can anyone help me get this working?

    Ya, that's fine but the command line I want to pass is:
    d:\j2sdk1.4.0\bin\rmiregistry.exe -J-Djava.class.path=d:\my dir with spaces\MyJar.jar;d:\my more dir with spaces\MyJar2.jar 1099
    If I say
    arg[0]="d:\\j2sdk1.4.0\\bin\rmiregistry.exe";, that's finebut arg[1] is the problem
    if I say
    arg[1]="-J-Djava.class.path=d:\\my dir with spaces\MyJar.jar; d:\\my more dir with spaces\\MyJar2.jar";, then it definitely won't work on 9X machines and probably not on NT.
    if I break up arg[1] into:
    arg[1]="-J-Djava.class.path=";
    arg[2]="d:\\my dir with spaces\\MyJar.jar";
    arg[3]=";";
    arg[4]="d:\\my more dir with spaces\\MyJar2.jar";I'll need to put quotes around the two individual two class paths or else it won't work.
    I find though that if I put the classpath as follows
    d:\"my dir with spaces"\MyJar.jar then it seems to work.
    I think a regular expression function to search for any directory with spacees and then put quotes around it and reinsert it into the path would be the solution.

  • Runtime.exec() with envp[] array

    I ran into an unsual problem.
    If I set an env array variable to something (at least one pair), then certain applications fail to start through Runtime.exec(command[], env[]). For example, my own java classes that require various xml and ftp libraries. The particular exception has been mentioned on the forum ( ie. Unrecognized Windows Sockets error: 10106:).
    It has to do with environment variables not being set for new process. When I do NOT set env[] variable (or pass null) then current env is used in .exec() call and everything works fine.
    So my question is how do I set my environment variables and/or append them to existing set.Or said differently if I pass a non-null array, current env set is not copied over.
    thanks,
    eugene

    >
    It has to do with environment variables not being set for new process. When I do NOT set env[] variable (or pass null) then current env is used in .exec() call and everything works fine.
    So my question is how do I set my environment variables and/or append them to existing set.Or said differently if I pass a non-null array, current env set is not copied over.
    >
    If you're using 1.5, you can create a java.lang.ProcessBuilder object rather than calling Runtime.exec(). The ProcessBuilder inherits the environment of the calling process, but then allows you to update individual entries.
    In 1.4, I don't believe that you can get a complete copy of the invoker's environment.

  • Runtime.exec()

    Please check the code.
    String []envp = {"JAVA_HOME=C:/AdventNet/Simulator5_0/jre", "STKT_HOME=C:/AdventNet/Simulator5_0", "LD_LIBRARY_PATH=C:/AdventNet/Simulator5_0/lib",
                                   "PATH=%PATH%;C:/AdventNet/Simulator5_0/lib",
                                   "classpath=C:/AdventNet/Simulator5_0;C:/AdventNet/Simulator5_0/conf;C:/AdventNet/Simulator5_0/jars/AdventNetNPrevalent.jar;C:/AdventNet/Simulator5_0/jars/AdventNetLauncher.jar;C:/AdventNet/Simulator5_0/jars/AdventNetUpdateManagerInstaller.jar;C:/AdventNet/Simulator5_0/jars/AdventNetAgentRuntimeUtilities.jar;C:/AdventNet/Simulator5_0/jars/AdventNetAgentUIUtilities.jar;C:/AdventNet/Simulator5_0/jars/AdventNetAgentUtilities.jar;C:/AdventNet/Simulator5_0/jars/AdventNetAgentSimulatorRuntime.jar;C:/AdventNet/Simulator5_0/jars/AdventNetAgentSimulator.jar;C:/AdventNet/Simulator5_0/jars/AdventNetNetworkSimulator.jar;C:/AdventNet/Simulator5_0/jars/AdventNetNDT.jar;C:/AdventNet/Simulator5_0/jars/AdventNetSimulatorDB.jar;C:/AdventNet/Simulator5_0/jars/AdventNetSimulatorUtils.jar;C:/AdventNet/Simulator5_0/jars/AdventNetSimulatorUIUtils.jar;C:/AdventNet/Simulator5_0/jars/AdventNetAgentUtils.jar;C:/AdventNet/Simulator5_0/jars/AdventNetAgent.jar;C:/AdventNet/Simulator5_0/jars/AdventNetSnmp.jar;C:/AdventNet/Simulator5_0/jars/AdventNetSnmpAgent.jar;C:/AdventNet/Simulator5_0/jars/AdventNetSnmpAgentTools.jar;C:/AdventNet/Simulator5_0/jars/jaxp.jar;C:/AdventNet/Simulator5_0/jars/xalan.jar;C:/AdventNet/Simulator5_0/jars/MibBrowser.jar;C:/AdventNet/Simulator5_0/jars/crimson.jar;C:/AdventNet/Simulator5_0/jars/jython.jar;C:/AdventNet/Simulator5_0/jars/JimiProClasses.zip;C:/AdventNet/Simulator5_0/jars/ApiUtils.jar;C:/AdventNet/Simulator5_0/jars/AdventNetUtils.jar;C:/AdventNet/Simulator5_0/jars/AdventNetTL1.jar;C:/AdventNet/Simulator5_0/jars/AdventNetTL1Agent.jar;C:/AdventNet/Simulator5_0/jars/AdventNetTL1AgentTools.jar;C:/AdventNet/Simulator5_0/jars/AdventNetTL1Tools.jar;C:/AdventNet/Simulator5_0/jars/AdventNetLogging.jar;C:/AdventNet/Simulator5_0/jars/AdventNetProBeansBeanInfo.jar;C:/AdventNet/Simulator5_0/jars/AdventNetProBeans.jar;C:/AdventNet/Simulator5_0/jars/AdventNetUI.jar;C:/AdventNet/Simulator5_0/jars/AdventNetUIBeanInfo.jar;C:/AdventNet/Simulator5_0/jars/mysql_connector.jar;C:/AdventNet/Simulator5_0/jars/AdventNetCCLUtils.jar;C:/AdventNet/Simulator5_0/jars/AdventNetCCLXMLParser.jar;C:/AdventNet/Simulator5_0/jars/AdventNetTftp.jar;C:/AdventNet/Simulator5_0/jars/ftp.jar",
                                   "THREADS_FLAG=native", "JAVA_COMPILER=NONE" };
              //String cmd = "%JAVA_HOME%/bin/java -mx200M  -Dpython.home=./jython -Djython.jar=./jars/jython.jar -Dpython.packages.paths=jython.jar,sun.boot.class.path com.adventnet.simulator.netsim.NetworkSimulator  -net networks/nn/nn.net %*";
              String cmd = "C:/AdventNet/Simulator5_0/jre/bin/java -mx200M  -Dpython.home=C:/AdventNet/Simulator5_0/jython -Djython.jar=C:/AdventNet/Simulator5_0/jars/jython.jar -Dpython.packages.paths=jython.jar,sun.boot.class.path com.adventnet.simulator.netsim.NetworkSimulator  -net networks/NetworkDemo/NetworkDemo.net >jerr.txt";
              try {
                   Runtime.getRuntime().exec(cmd,envp,new File("C:/AdventNet/Simulator5_0/"));
              } catch(Exception e) {
                   e.printStackTrace();
              }The same thing if I try in command line prompt of Windows XP, I dont find any problem. The java class executes. But when I try with above approach it fails. But I dont find any error or problem. Please tell me how could I check the output, the error executed by the command provided in exec() method. If I can see the output, I can understand the problem.

    I can't be bothered to read all that, and you really should have provided a better explanation of what the problem is.
    However, at a guess, I think it might be the %% variable names. Those are expanded by the command shell when you run cmd.exe, but when you just pass them as args to Runtime.exec, it doesn't expand them.
    I know for a fact a similar thing happens when you try to use $ variable names on Unix, but I'm not very familiar with cmd.exe, so this is just a guess.
    You might try either replacing them here with their System.getEnv() values, or changing your command to cmd.exe, and then passing the rest--including the invocation of the vm--as args. I think it's something like "cmd.exe /c C:\\...blah...\\java ...etc...." but check the help on cmd.exe /? for details.

  • Set Path to DLLs for Runtime.exec(...)

    I have got a little server application that creates a Process of an external application. (eg Example1.exe or Example2.exe - which one is to be called is configurable via property files)
    All of these external apps rely on a couple of DLLs, that are distributed seperately from the ExampleX.exe.
    So my directory structure looks something like this:
    /Server (contains my java app)
    /Server/dll (contains the dlls)
    /Server/app (contains ExampleX.exe files)
    How do I configure my Runtime.exec(...) so that it can supply a PATH info to my DLLs?
    How about the ...exec(String command, String[] envp, File dir) call?
    -> It already works when the DLLs are in the same dir as my .exe files.
    -> I would like to avoid setting a global PATH to my DLLs in the OS.
    Has anybody already dug itself through this pile?

    Solved my problem, awarded the Dukes to myself! ;-)
    Here's what I did in case somebody else has similar probs:
    The envp Parameter didn't work for me. The Application and the DLLs were found but the Subprocess was somehow screwed up - the Threading didn't work right. (I have no clue how that could be, but whatever...)
    Anyway I could put the path to the DLLs in the PATH info of my startup script for the Java-Server. The subprocess inherits that information.
    I used relative path info there so that nobody has to fiddle around in the script when the application is moved to different directories.
    The only thing you have to do then is to set the present working directory of the subprocess to the location of the server via ...execute(String, String[], File)
    You need to supply thecomplete path to the application in the first String parameter that way but all in all this semms to be the most sensible way to do it.

  • How to exec command with parameters through runtime.exec()

    im trying to run a command prompt passing in parameters. Right now im creating a .bat file like this
    c:
    cd C:\SOMEDIR
    ant deploy moreparameters
    and then passing in the file name into the exec command. It is running fine but im trying to use the runtime.destroy() command and it doesnt close the ant command, it only closes the bat file which was already closed. Is there a command I could pass into the exec() method to run the ant command with the parameters without using a bat file?

    im getting a CreateProcess: ant deploy -Dswasm=swasm error=2
    When i try to do
    cmds[0] = "ant";
    cmds[1] = "deploy";
    cmds[2] = "-Dswasm=all-bs";
    Process p = runTime.exec(cmds, null, new File("C:\\Program Files\\apache-ant-1.6.1\\bin"));
    its like it cant find ant. But it finds java command fine. What should i pass into the second parameter, it says "If envp is null, the subprocess inherits the environment settings of the current process. " Does that mean it will take the window system enviroment variables? if not what string would i pass in to set where ant is?

  • IOException File not found - While using Runtime.exec

    Hey All,
    I have written a Java application which needs to start up another external application. I have executables for that external application for different platforms (Win32, PPC and Linux). When the Java application is started it detects the OS and starts up the right executable according to the OS. The executable loads up fine on Windows without any problems. But in both Linux and Max OS X I get this exception:
    java.io.IOException: java.io.IOException: "/home/vilas/Documents/Project/build/CLISP/linux/lisp.run": not found
            at java.lang.UNIXProcess.<init>(UNIXProcess.java:143)
            at java.lang.Runtime.execInternal(Native Method)
            at java.lang.Runtime.exec(Runtime.java:566)
            at java.lang.Runtime.exec(Runtime.java:428)
            at jplan.communication.lispserver.LispServer.startupServer(LispServer.java:143)
            at jplan.communication.lispserver.LispServer.run(LispServer.java:109)
            at java.lang.Thread.run(Thread.java:534)lisp.run has all the necessary permissions. If I copy the string (/home/vilas/Documents/Project/build/CLISP/linux/lisp.run) and paste it in a terminal and press enter, the application starts up fine without any problems!! Can you please tell me what could be going wrong?
    The following extra information maybe helpfull:
    1) I use the exec(String command, String[] envp, File dir) version of exec.
    2) The complete format of the command is as follows (one long string):
    "/home/vilas/Documents/Project/build/CLISP/linux/lisp.run" -B "/home/vilas/Documents/Project/build/CLISP/linux" -M "/home/vilas/Documents/Project/build/CLISP/linux/lispinit.mem" -i loader.lisp
    Thanks in advance for your time and efforts.

    I found the problem after extensively searing the forums (looking upto page 4 !! of the results). The problem was that I was using quotes to surround the paths in the command. If you copy and paste it in a terminal it will work fine but it does not work with runtime.exec. I am not sure, but I think the reason is that when a terminal is used, some pre-processing of the commands take place before they are passed onto the OS(shell). But while using runtime.exec, that pre-processing is not peformed and therefore some things will not work.
    In order to fix the problem, I use quotes only when the OS is windows. In other cases(OS X, Linux) I escape the spaces i.e. replace " " with "\ ".
    PS: The executable is a binary compiled from C code.

  • Running C++ application from Runtime.exec

    Hello everybody
    I am trying to run a c++ executable file(myap.exe) using Runtime.getruntime().exec("myap"), nothing happend!.
    Can anyone help me please.

    Where is located the file 'myapp.exe' ?
    If not in directory that is in 'PATH' varable, you need to use :
    Runtime.exec(String command, String[] envp, File dir)
    Executes the specified string command in a separate process with the specified environment and working directory.
    Floweb

  • Runtime.exec() ... executing a java jar from within an NT command file

    Hello,
    I spent the better part of yesterday seeking insight to this with little success. So I hope someone here can direct me in a productive direction.
    I set-up my runtime.exec in a manner similar to the article on javaworld.com which is often referred to here, with two threads to empty the output and error streams of the NT command file I am executing.
    The command file works perfectly from the command line.
    I am currently attempting to build a gui which will automate regression testing for another application. This requires third party software to be running prior to the execution of the test suite. This third party software is started using an NT command file. The command file sets up an environment (classpath, server flags, etc.) and then executes a jar file. When this command file is run from my Gui, the output is identical to the command being run from the command line. Then when the jar file is to be executed, the command file output shows a "file not found" error, but only when executed from my Gui.
    My call to runtime exec looks like this.
    cmdString = new String("commandtoexecute");
    fileLoc = new String("Fully qualified path to command file");
    String [] envp = new String[0];
    testProcess = Runtime.getRuntime().exec(cmdString, envp, fileLoc);
    // some code to process the output streams of testProcess
    Other Info:
    Gui currently executed within Eclipse IDE
    BEA WebLogic is the third party software

    First, my app has the requirement of allowing the user to start WebLogic if it is not already running.Unfortunately, I can't change the requirement.
    But I would say that in a production environment WebLogic should always be running.
    I guess it's an assumption that I'd make a priori. You're jumping through too many hoops to accomplish something that is better solved with a phone call to the server admin: "Please start the WebLogic service."
    .... Side question ... any recommendations on detecting if it is already running? grin
    Yes, call the server admin and ask why you can't have 99.999% availability of a critical resource.
    Second, development is on a hardened system (i.e. very
    long time getting approval for additional software on
    the system).Cactus and JUnit are both open source. No fees involved. If you can install a JAR, you can use these tools.
    Better yet, you can drive them automatically as part of your Ant build process. A GUI implies a person in front of it to start and monitor the tests. JUnit and Ant are all about automating these things so they're run every time you rebuild and redeploy the code. You get XML reports on test results that are displayable in a browser. You can even e-mail the test summary to all developers so they can see if a test broke the build. If a test breaks, you don't deploy. That's the way to go, IMO.
    When you have a working Ant build.xml, the next step is to automate the build completely using a tool like ThoughtWorks' CruiseControl.
    Thank you for you suggestions though. I will read up on Cactus to see if it could help me here.You're welcome. Good luck. Sorry that I'm not more help.

  • PATH Setting using Runtime.exec() on a UNIX env?

    Hi,
    How do we set the PATH using Runtime.exec() on a UNIX Env?
    I've tried the 'export' command and 'setenv' command but it throws an exception saying 'export' and 'setenv' not found.
    objProcess = Runtime.getRuntime().exec("setenv PATH /opt/ibm/java2-x86_64-50/bin");+
    Please suggest.
    Thanks,
    Tanu

    Your experimenting with the stuff could shed light on the question, whether the outcome is influenced by the relying of the started process on elements of the starting environment other than PATH.
    String[] envp=new String[1];
    envp[0]="PATH=/jdk1.5/bin";
    Runtime rt=Runtime.getRuntime();
    Process proc=rt.exec("java Test",envp);

Maybe you are looking for

  • Final Cut Server as "regular" DAM

    Hi people, I've been thinking if Final Cut Server can be used as a "regular" DAM, just like Extensis Portfolio, cataloging mostly images and nothing related to video media. If it can, that's a definitely good news, specially because Extensis solution

  • Rejection report

    Dear All , Pl guide for the Rejection Qty  report & scrap Qty  report for QM ? Edited by: venky  shree on Feb 18, 2009 12:18 PM

  • TextArea Scrollbar problem

    I am starting to elarn flex and as a learning project I decided to make a simple RSS reader for one of my websites. I plan to release it as an Android app. The thing is I found a small problem with a textArea that has HTML text inside it. The text ge

  • Developing a WS Client

    Hey, I am completely new to javax-ws. I have to create a WS client which interacts with a WS by sending/receiving a SOAP message. End goal of this application is to convert a java object into a SOAP message, send SOAP message to WS, get back SOAP res

  • BAdi to be used to update ECC PO

    Hi, We are using SRM5.0 classic Scenario, I have tried ME_PROCESS_PO_CUST,BBP_INBOUND_PO_BADI, ECS_PO_BACK BAdis but was not able to replicate/ perform modification to the data passed to the ECC PO.even simple changes to volume field or any other fie