Adding environment variables to Runtime.exec()

Hello,
I'm trying to use Runtime.getRuntime().exec(command, envp);
When envp is null the program launches properly. (the doc says that the subprocess inherits the environment settings of the current process).
I want to add an environment variable, so when I use an array containing only my variable (envp), the process fails. I guess it needs the variables of the current process (as used when using null).
In that case, How adding a variable instead of replacing the default ??????
(I did not see any way to retrieve these default variables so I can concatenate with the custom one)
Thanks !

Use a wrapper script that is launched with a default environment and first sets the custom variable and goes on with your program.

Similar Messages

  • Accesing environment variables from Runtime.exec()

    Hi All,
    I have a problem for which I need help. I have a property BLAH set to "abc" in my ~/.bashrc. My programme looks as following.
    Runtime rt = Runtime.getRuntime();
    String command="java -Dext.prop=${BLAH} Test1";
    //Even following also dont work I removed curly braces
    // String command="java -Dext.prop=$BLAH Test1";
    try {
    rt.exec(command);
    } catch (IOException e) {
    e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
    I just want to set the value of environment variable to a property "ext.prop" and in class Test1 I would like to access it as System.getProperty("ext.prop"). The problem is that the value of System.getProperty("ext.prop") is $BLAH instead of "abc" which I set in my ~/.bashrc.
    If I execute the same command ("java -Dext.prop=${BLAH} Test1") from command prompt then I don't have any problem. I tried in another way also that is
    Edited by: ragsger on Dec 22, 2008 12:59 PM
    Edited by: ragsger on Dec 22, 2008 1:00 PM

    Replacing $BLAH with the value of the environment variable BLAH is handled by the shell and since you don't call a shell, you'll have to do that on your own.
    System.getenv("BLAH") will get the value.

  • Adding environment variable in build.xml(ANT)

    Hi,
    I need some information Regarding ANT,
    the problem is i have to add a property file in build.xml (as a environment varialble) so that i can read it in my java code. as
    System.getProperty("").
    Please sugggest me how to set environment variable in build.xml(ANT)
    Thanks
    Edited by: fdfddf on Apr 7, 2008 3:20 PM

    Hi Jakain, yep thanks for your information but my manager wants that way to do..
    he wanted me to set property file as a environment file using build.xml as this property file changes dynamically..
    can you suggest me

  • Adding Environment Variables in X11

    Could anyone please tell me how can I do it?

    See, for example,
    http://developer.apple.com/qa/qa2001/qa1067.html
    http://www.astro.washington.edu/owen/AquaEnvVar.html
    HTH

  • Environment of process created by Runtime.exec()

    Can anyone describe the interactions of the process environment created by Runtime.exec()?
    For example, if Runtime.exec() is used as follows:
    Runtime.exec("cmd /K somebatfile");
    Is the environment preserved throughout the execution of somebatfile?
    Rather, if the classpath, working directory, etc. is changed within "somebatfile" are those changes still preserved by the cmd shell if it is executed this way from Runtime?

    That is the way I thought things worked. Thanx.
    However, when I start my command script inside of a shell (with "cmd /K") I get a "file not found" error. The command generating the error is a java call loading a executable jar which uses jni to open sockets and I have no Idea what else. (I know about the sockets because of the failed socket messages that are generated after the file not found error). The source code for the launched application is not available.
    If you can provide some other insight I would appreciate it.

  • Environment variable setting not working in the report

    Hi everybody,
    Iam facing a problem related to reports10g ids. database is 9i
    My basic requirement is ,i want to show a report out put in a BRAZILIAN PORTUGUESE Language.
    For this purpose i configured the report_server.conf file like
    <environment id="PS">
    <envVariable name="NLS_LANG" value="BRAZILIAN PORTUGUESE_BRAZIL.WE8MSWIN1252"/>
    </environment>
    After that i added a entry along with the web.show_documents(using for calling the report)envid=PS
    when iam running the report ,report server is only converting one date field in to portuguese ,rest of them are same as in the database.
    Actualy i dont know where i did wrong.if anybody know please help meee
    Thanks in advance
    mathew

    Hello Matthew,
    See Note:231051.1, Dynamic Environment Switching In Reports 9i for an example of setting your environment variables at runtime. It uses REPORTS_PATH, there is also an entry for NLS_LANG in the reports.sh file (in UNIX). This setting is causing the conflict when you try to set it at runtime.
    I think you have to remove the entry from reports.sh config file and then you will have to pass the parm at runtime everytime.
    I hope this helps!
    Tony

  • Environment variable setting not working

    Hi Frank,
    Iam reposting this requst to forms forum because i did~t get any response from report forum.Please help me frank.
    Iam facing a problem related to reports10g ids. database is 9i
    My basic requirement is ,i want to show a report out put in a BRAZILIAN PORTUGUESE Language.
    For this purpose i configured the report_server.conf file like
    <environment id="PS">
    <envVariable name="NLS_LANG" value="BRAZILIAN PORTUGUESE_BRAZIL.WE8MSWIN1252"/>
    </environment>
    After that i added a entry along with the web.show_documents(using for calling the report)envid=PS
    when iam running the report ,report server is only converting one date field in to portuguese ,rest of them are same as in the database.
    Actualy i dont know where i did wrong.if anybody know please help meee
    Thanks in advance
    mathew

    Hello Matthew,
    See Note:231051.1, Dynamic Environment Switching In Reports 9i for an example of setting your environment variables at runtime. It uses REPORTS_PATH, there is also an entry for NLS_LANG in the reports.sh file (in UNIX). This setting is causing the conflict when you try to set it at runtime.
    I think you have to remove the entry from reports.sh config file and then you will have to pass the parm at runtime everytime.
    I hope this helps!
    Tony

  • OMB PLUS - Problem passing Unix environment variables to OMBPlus

    Due to a requirement to encapsulate deployment of OWB applications, we currently start OMBPlus.sh from our own wrapper ksh script (deploy.ksh) in order to get the new / changed application into the target control center etc.
    We now have a new requirement that means we need to pass the content of the Unix environment across to OMBPlus.sh (and from thence into our deployment tcl scripts).
    No problem, if you believe the tcl documentation. The entire Unix environement gets dumped into a hash array called 'env', so you can get the variable's value out just by saying $env(unix_valraible).
    Sounds great, it should work a treat.
    Except OMBPlus only silghtly resembles tclsh.
    The 'env' that gets into OMBPlus bears practically no resemblance to the 'env' that existed before OMBPlus.sh got invoked.
    Does anyone have:
    a decent explanation for why the env gets scrambled (and how to avoid it) ?
    or an alternative method of getting the Unix environment varaible values into OMBPlus ?
    Please do not propose passing them all on the command line because (would you beleive it) the values are database passwords !
    Edited by: user10466244 on 23.10.2008 09:28

    Unfortunately, the java implementation of TCL that Oracle used as the basis for OMB+ is NOT a fully-featured implementation. Just try using packages...
    However, and understanding why you don't want to hard-code passwords into a file, you can always edit the setowbenv.sh file in your owb/bin/unix directory to grab your specific shell environment variables and propogate them to the java session.
    towards the bottom of this env file you will see a section that looks something like:
    JDK_HOME=../../../jdk
    OWB_HOME=/owb
    ORA_HOME=/owb
    OEM_HOME=/owb
    IAS_HOME=/owb
    ORACLE_HOME=/owb
    CLASSPATH=Personalties.jar:../admin:$MIMB_JAR:
    CLASSPATH_LAUNCHER="-classpath ../admin:../admin/launcher.jar:$CLASSPATH: -DOWB_HOME=$OWB_HOME -DJDK_HOME=$JDK_HOME -DORA_HOME=$ORA_HOME -DOEM_HOME=$OEM_HOME -DIAS_HOME=$IAS_HOME -Doracle.net.tns_admin=$ORA_HOME/network/admin Launcher ../admin/owb.classpath"
    export ORA_HOME
    export OWB_HOME
    export JDK_HOME
    export OEM_HOME
    export IAS_HOME
    export ORACLE_HOME
    You could add in the environment variables that you want propogated, include them into the CLASSPATH_LAUNCHER, and then they will turn up in your OMB+ session env array.
    e.g., to propgate an environment variable called MY_DATABASE_PASSWORD you would:
    JDK_HOME=../../../jdk
    OWB_HOME=/owb
    ORA_HOME=/owb
    OEM_HOME=/owb
    IAS_HOME=/owb
    ORACLE_HOME=/owb
    CLASSPATH=Personalties.jar:../admin:$MIMB_JAR:
    CLASSPATH_LAUNCHER="-classpath ../admin:../admin/launcher.jar:$CLASSPATH: -DOWB_HOME=$OWB_HOME -DMY_DATABASE_PASSWORD=${MY_DATABASE_PASSWORD} -DJDK_HOME=$JDK_HOME -DORA_HOME=$ORA_HOME -DOEM_HOME=$OEM_HOME -DIAS_HOME=$IAS_HOME -Doracle.net.tns_admin=$ORA_HOME/network/admin Launcher ../admin/owb.classpath"
    export ORA_HOME
    export OWB_HOME
    export JDK_HOME
    export OEM_HOME
    export IAS_HOME
    export ORACLE_HOME
    So now you have no protected data hardcoded, it will pick up your specific environment variables at runtime, and when you start OMB+ you will be able to:
    array get env MY_DATABASE_PASSWORD.
    cheers,
    Mike

  • Process core dumps when spawned by Runtime.exec()

    I am using a Runtime.exec() command to spawn a local executable process on HP-UX. The local process (C++ executable) starts and is functional, though at a certain point during operation, the process creates a segmentation fault and core dumps. If the same process is spawned manully from a shell, this does not occur.
    The process cores at the same point every time (a call to free+ in the system libC library). I have duplicated as much of my shell environment in the Runtime.exec() call as possible. Also, this issue does not occur on AIX or Linux (ports of my code to those platforms).
    What is the fundimental difference between spawning a process from a shell V.S. the JVM spawning the process that could cause this difference in behavior?
    java version "1.4.2.07"
    Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.2.07-050121-15:53)
    Java HotSpot(TM) Server VM (build 1.4.2 1.4.2.07-050121-17:30-PA_RISC2.0 PA2.0 (aCC_AP), mixed mode)

    We are currently having the same problem, it is killing us.
    We have upgraded to jdk 1.6u16 and still have the problem.
    We think it is related to sparc platform we had been running for some time with same code on X86 server
    Our solaris release is: Solaris 10 11/06 s10s_u3wos_10 SPARC
    We can't get a reproducible small test case. It is getting us most often when the JVM running our
    appserver uses the Runtime.getRuntime().exec(cmd);
    We are jumping through hoops looking for workaround. We are trying to write a command server that can
    have the command sent through a socket and have all the ouput sent back over the same socket.
    That way the app server JVM is not the one doing the fork and exec.

  • Runtime.exec and setting environment variables

    Runtime.exec and setting environment variables
    I need a decent example which works on Windows.
    Got any?

    Thank you.
    I was hoping for an example of the use of
    http://java.sun.com/j2se/1.4.1/docs/api/java/lang/Runti
    e.html#exec(java.lang.String,%20java.lang.String[]) or
    http://java.sun.com/j2se/1.4.1/docs/api/java/lang/Runti
    e.html#exec(java.lang.String,%20java.lang.String[],%20j
    va.io.File) which take environment variable
    information such as PATH.
    The reason is because there is a library which is
    being loaded via loadLibrary (
    http://java.sun.com/j2se/1.4.1/docs/api/java/lang/Syste
    .html#loadLibrary(java.lang.String) ). However, for
    the child process to find the library the PATH needs
    to be updated.
    Any example regarding changing the PATH variable via
    Java so that libraries can be loaded and processes
    created? (Perhaps, I should make a new post and
    restate the question with this more explicit
    information?)
    That won't work. LoadLibrary occurs in the JVM environment. As I said you can't change the JVM environment via exec().
    If the shared library needs something in the path then you are going to have to set the path before your application starts up.
    If you just need to load the library from someplace that is not on the path then you should be using System.load().

  • Using Runtime.exec() to export variables

    I'm developing some code on an AIX machine using ksh (korn shell)
    I need to export a list of variables and then execute a program.
    As far as I can tell, each exec call is a seperate process. So it starts a new shell, runs the command, then exits the shell. I believe that the variables I am attempting to export aren't being saved.
    I've used the following commands:
         export[0] = "sh";
         export[1] = "-c";
         export[2] = "export";
         env[0] = "SYSTEM_VAR=/usr/bin/dir/example";
    sysCall.sysEnvCall(export,env);
    public int sysEnvCall(String[] sysCommand, String[] sysEnv){
         try{
              proc = rt.exec(sysCommand, sysEnv);
              proc.waitFor();
    errorHandler = new SystemStreamHandler(proc.getErrorStream(), "ERROR");           
    outputHandler = new SystemStreamHandler(proc.getInputStream(), "OUTPUT");
         errorHandler.start();
         outputHandler.start();
         exitVal = proc.waitFor();
         if(exitVal > 0)
                   System.out.println("ExitValue: " + exitVal);
         return 0;
              catch(Throwable t)
                   t.printStackTrace();
                   return 1;
              }Please forgive the formatting, it didn't copy/paste well.
    I've tried numerous other export command formats, none of which have worked. If I do an export command followed by either a echo $NEWVAR, or printenv NEWVAR, they are blank.
    I also tried the processBuilder object to no avail. Apparently my system doesn't allow me to "put"/edit system variables.
    If at all possible I would like to run concurrent commands without starting a new shell everytime.
    If anyone has any ideas/suggestions I would greatly appreciate it.
    Thanks much
    Paul

    Once you start a Process, environment variables set in that process will NOT affect the parent process.
    That is a fundamental design choice in UNIX, and you cannot do anything about that.
    Instead, if you just want to set a complicated set of environment variables
    for a new subprocess, you can use ProcessBuilder to do that.
    I also tried the processBuilder object to no avail.
    Apparently my system doesn't allow me to "put"/edit
    system variables.I doubt that. Please post the code for how you tried that.

  • How to get system Environment variable?

    How to get system Environment variable without using jni?
    just like "JAVA_HOME" or "PATH"...
    Any reply is help to me!! :-)

    Thx for your reply...
    I get it!!!
    Read environment variables from an application
    Start the JVM with the "-D" switch to pass properties to the application and read them with the System.getProperty() method. SET myvar=Hello world
    SET myothervar=nothing
    java -Dmyvar="%myvar%" -Dmyothervar="%myothervar%" myClass
    then in myClass String myvar = System.getProperty("myvar");
    String myothervar = System.getProperty("myothervar");
    This is useful when using a JAVA program as a CGI.
    (DOS bat file acting as a CGI) java -DREQUEST_METHOD="%REQUEST_METHOD%"
    -DQUERY_STRING="%QUERY_STRING%"
    javaCGI
    If you don't know in advance, the name of the variable to be passed to the JVM, then there is no 100% Java way to retrieve them.
    NOTE: JDK1.5 provides a way to achieve this, see this HowTo.
    One approach (not the easiest one), is to use a JNI call to fetch the variables, see this HowTo.
    A more low-tech way, is to launch the appropriate call to the operating system and capture the output. The following snippet puts all environment variables in a Properties class and display the value the TEMP variable. import java.io.*;
    import java.util.*;
    public class ReadEnv {
    public static Properties getEnvVars() throws Throwable {
    Process p = null;
    Properties envVars = new Properties();
    Runtime r = Runtime.getRuntime();
    String OS = System.getProperty("os.name").toLowerCase();
    // System.out.println(OS);
    if (OS.indexOf("windows 9") > -1) {
    p = r.exec( "command.com /c set" );
    else if ( (OS.indexOf("nt") > -1)
    || (OS.indexOf("windows 2000") > -1 )
    || (OS.indexOf("windows xp") > -1) ) {
    // thanks to JuanFran for the xp fix!
    p = r.exec( "cmd.exe /c set" );
    else {
    // our last hope, we assume Unix (thanks to H. Ware for the fix)
    p = r.exec( "env" );
    BufferedReader br = new BufferedReader
    ( new InputStreamReader( p.getInputStream() ) );
    String line;
    while( (line = br.readLine()) != null ) {
    int idx = line.indexOf( '=' );
    String key = line.substring( 0, idx );
    String value = line.substring( idx+1 );
    envVars.setProperty( key, value );
    // System.out.println( key + " = " + value );
    return envVars;
    public static void main(String args[]) {
    try {
    Properties p = ReadEnv.getEnvVars();
    System.out.println("the current value of TEMP is : " +
    p.getProperty("TEMP"));
    catch (Throwable e) {
    e.printStackTrace();
    Thanks to W.Rijnders for the W2K fix.
    An update from Van Ly :
    I found that, on Windows 2003 server, the property value for "os.name" is actually "windows 2003." So either that has to be added to the bunch of tests or just relax the comparison strings a bit: else if ( (OS.indexOf("nt") > -1)
    || (OS.indexOf("windows 2000") > -1 )
    || (OS.indexOf("windows 2003") > -1 ) // works but is quite specific to 2003
    || (OS.indexOf("windows xp") > -1) ) {
    else if ( (OS.indexOf("nt") > -1)
    || (OS.indexOf("windows 20") > -1 ) // probably is better since no other OS would return "windows" anyway
    || (OS.indexOf("windows xp") > -1) ) {
    I started with "windows 200" but thought "what the hell" and made it "windows 20" to lengthen its longivity. You could push it further and use "windows 2," I suppose. The only thing to watch out for is to not overlap with "windows 9."
    On Windows, pre-JDK 1.2 JVM has trouble reading the Output stream directly from the SET command, it never returns. Here 2 ways to bypass this behaviour.
    First, instead of calling directly the SET command, we use a BAT file, after the SET command we print a known string. Then, in Java, when we read this known string, we exit from loop. [env.bat]
    @set
    @echo **end
    [java]
    if (OS.indexOf("windows") > -1) {
    p = r.exec( "env.bat" );
    while( (line = br.readLine()) != null ) {
    if (line.indexOf("**end")>-1) break;
    int idx = line.indexOf( '=' );
    String key = line.substring( 0, idx );
    String value = line.substring( idx+1 );
    hash.put( key, value );
    System.out.println( key + " = " + value );
    The other solution is to send the result of the SET command to file and then read the file from Java. ...
    if (OS.indexOf("windows 9") > -1) {
    p = r.exec( "command.com /c set > envvar.txt" );
    else if ( (OS.indexOf("nt") > -1)
    || (OS.indexOf("windows 2000") > -1
    || (OS.indexOf("windows xp") > -1) ) {
    // thanks to JuanFran for the xp fix!
    p = r.exec( "cmd.exe /c set > envvar.txt" );
    // then read back the file
    Properties p = new Properties();
    p.load(new FileInputStream("envvar.txt"));
    Thanks to JP Daviau
    // UNIX
    public Properties getEnvironment() throws java.io.IOException {
    Properties env = new Properties();
    env.load(Runtime.getRuntime().exec("env").getInputStream());
    return env;
    Properties env = getEnvironment();
    String myEnvVar = env.get("MYENV_VAR");
    To read only one variable : // NT version , adaptation for other OS is left as an exercise...
    Process p = Runtime.getRuntime().exec("cmd.exe /c echo %MYVAR%");
    BufferedReader br = new BufferedReader
    ( new InputStreamReader( p.getInputStream() ) );
    String myvar = br.readLine();
    System.out.println(myvar);
    Java's System properties contains some useful informations about the environment, for example, the TEMP and PATH environment variables (on Windows). public class ShowSome {
    public static void main(String args[]){
    System.out.println("TEMP : " + System.getProperty("java.io.tmpdir"));
    System.out.println("PATH : " + System.getProperty("java.library.path"));
    System.out.println("CLASSPATH : " + System.getProperty("java.class.path"));
    System.out.println("SYSTEM DIR : " +
    System.getProperty("user.home")); // ex. c:\windows on Win9x system
    System.out.println("CURRENT DIR: " + System.getProperty("user.dir"));
    Here some tips from H. Ware about the PATH on different OS.
    PATH is not quite the same as library path. In unixes, they are completely different---the libraries typically have their own directories. System.out.println("the current value of PATH is: {" +
    p.getProperty("PATH")+"}");
    System.out.println("LIBPATH: {" +
    System.getProperty("java.library.path")+"}");
    gives the current value of PATH is:
    {/home/hware/bin:/usr/local/bin:/usr/xpg4/bin:/opt/SUNWspro/bin:/usr/ccs/bin:
    /usr/ucb:/bin:/usr/bin:/home/hware/linux-bin:/usr/openwin/bin/:/usr/games/:
    /usr/local/games:/usr/ccs/lib/:/usr/new:/usr/sbin/:/sbin/:/usr/hosts/:
    /usr/openwin/lib:/usr/X11/bin:/usr/bin/X11/:/usr/local/bin/X11:
    /usr/bin/pbmplus:/usr/etc/:/usr/dt/bin/:/usr/lib:/usr/lib/lp/postscript:
    /usr/lib/nis:/usr/share/bin:/usr/share/bin/X11:
    /home/hware/work/cdk/main/cdk/../bin:/home/hware/work/cdk/main/cdk/bin:.}
    LIBPATH:
    {/usr/lib/j2re1.3/lib/i386:/usr/lib/j2re1.3/lib/i386/native_threads:
    /usr/lib/j2re1.3/lib/i386/client:/usr/lib/j2sdk1.3/lib/i386:/usr/lib:/lib}
    on my linux workstation. (java added all those execpt /lib and /usr/lib). But these two lines aren't the same on window either:
    This system is windows nt the current value of PATH is:
    {d:\OrbixWeb3.2\bin;D:\jdk1.3\bin;c:\depot\cdk\main\cdk\bin;c:\depot\
    cdk\main\cdk\..\bin;d:\OrbixWeb3.2\bin;D:\Program
    Files\IBM\GSK\lib;H:\pvcs65\VM\win32\bin;c:\cygnus
    \cygwin-b20\H-i586-cygwin32\bin;d:\cfn\bin;D:\orant\bin;C:\WINNT\system32;C:\WINNT;
    C:\Program Files\Dell\OpenManage\Resolution Assistant\Common\bin;
    d:\Program Files\Symantec\pcAnywhere;
    C:\Program Files\Executive Software\DiskeeperServer\;C:\Program Files\Perforce}
    LIBPATH:
    {D:\jdk1.3\bin;.;C:\WINNT\System32;C:\WINNT;d:\OrbixWeb3.2\bin;D:\jdk1.3\bin;
    c:\depot\cdk\main\cdk\bin;c:\depot\cdk\main\cdk\..\bin;
    d:\OrbixWeb3.2\bin;D:\Program Files\IBM\GSK\lib;
    H:\pvcs65\VM\win32\bin;c:\cygnus\cygwin-b20\H-i586-cygwin32\bin;d:\cfn\bin;
    D:\orant\bin;C:\WINNT\system32;
    C:\WINNT;C:\Program Files\Dell\OpenManage\ResolutionAssistant\Common\bin;
    d:\Program Files\Symantec\pcAnywhere;
    C:\Program Files\Executive Software\DiskeeperServer\;C:\Program Files\Perforce}

  • Runtime.exec() batch file problem

    Hi folks,
    i have a little problem when I want to execute a batch file through java's runtime.exec() method.
    the execution of a very simple batchfile works (for example opening notepad or other stuff), but I have problems with the following batch file (although it's still simple):
    net use s: \\Dd-nt-fs\Dsmp15_files
    set DSCFG=c:\dscfg
    set PSPATH=c:\adproof
    set ora_path=C:\oracle\ora92
    set path=S:\Dsmp_Q4_2004\Bin;%ora_path%\bin;%path%;
    set nd_font=S:\Dsmp_Q4_2004\Fonts
    set nxPS_FONT_DIR=%ND_FONT%
    set PSPATH=c:\adproof
    set PSFORMS=S:\Dsmp_Q4_2004\PsForms\Telenor
    s:
    cd S:\Dsmp_Q4_2004\bin
    S:\Dsmp_Q4_2004\Dsmp_Reports\Telenor\adproof.exe DBUSER=a_user DBPSWD=a_pswd DBSTR=dbstr ADINFO=adinfo.lst TASKID=a_taskid
    my guess is that there is a problem with the setting of environment variables which correspond to the drive s:
    I mannually added the batchfile (line by line) and looked whether it got through to the command which executes the adproof.exe file: for example the below batchfile worked:
    set DSCFG=c:\dscfg
    set PSPATH=c:\adproof
    set ora_path=C:\oracle\ora92
    s:
    cd S:\Dsmp_Q4_2004\bin
    S:\Dsmp_Q4_2004\Dsmp_Reports\Telenor\adproof.exe DBUSER=a_user DBPSWD=a_pswd DBSTR=dbstr ADINFO=adinfo.lst TASKID=a_taskid
    Here is the java code: in which i execute the batch file:
    Runtime rt = Runtime.getRuntime();
    Process proc = rt.exec("net use s: \\\\Dd-nt-fs\\DSMP15_FILES");
    BufferedReader  b = new BufferedReader(new InputStreamReader(proc.getErrorStream()));
    while( (line=b.readLine())!=null) {
          System.out.println(line);
    int exitVal = proc.waitFor();
    System.out.println("Exit Value = "  + exitVal);
    String[] cmd = new String[1];
    cmd[0] = "C:\\Documents and Settings\\tikmi\\My Documents\\mysources\\DSMP Prototype\\print\\hallo3.bat";
    // here i declared the needed settings of the environment variable and pass that array to the exec() method                   
    String[] env = new String[8];
    env[0] = "DSCFG=c:\\dscfg";
    env[1] = "ORA_PATH=C:\\oracle\\ora92";
    env[2] = "PSPATH=C:\\Documents and Settings\\tikmi\\My Documents\\mysources\\DSMP Prototype\\print";
    env[3] = "ND_FONT=S:\\Dsmp_Q4_2004\\Fonts";
    env[4] = "nxPS_FONT_DIR=%ND_FONT%";
    env[5] = "PSFORMS=S:\\Dsmp_Q4_2004\\PsForms\\Telenor";
    env[6] = "ND_PATH=S:\\Dsmp_Q4_2004\\resource";
    env[7] = "PATH=S:\\Dsmp_Q4_2004\\Bin;%ORA_PATH%\\BIN;%ND_PATH%;%PATH%;";
    rt  = Runtime.getRuntime();
    proc = rt.exec(cmd, env);
    b = new BufferedReader(new InputStreamReader(proc.getErrorStream()));
    while( (line=b.readLine())!=null) {
              System.out.println(line);
    exitVal = proc.waitFor();
    System.out.println("Exit Value = "  + exitVal);Maybe someone else had similar problems or can help me solving that problem.
    Any advice would be very appreciated.
    regards
    mirkolino

    finally I got it working now.
    for those who are interested in the problem, my code that's now working is the following
    Runtime rt = Runtime.getRuntime();
                            Process proc = null;
                            String cmd = "cmd.exe /c c:\\adproof\\hallo3.bat";
                            proc = rt.exec(cmd);
                            InputStream in = proc.getInputStream();
                            BufferedReader br = new BufferedReader ( new InputStreamReader(in));
                            String line;
                            while( (line=br.readLine()) != null) {
                                System.out.println(line);
                            int exit = proc.waitFor();
                            System.out.println();
                            System.out.println("Process exited with: " + exit);the problem was, that i have to handle and read the input stream
    thanks for you help
    greetings from mirkolino

  • Settting environment variables

    Oracle 9i AS on HP_UX.
    From within the servlet application I use Runtime.Exec() to start another process but it doesn't have access to the environment variables it needs, e.g. LD_LIBARY_PATH, even though these have been set in .profile.
    I have also tried adding them to jserv.properties, but still no result.
    Can anyone explain how to make environment variables available within the servlet application
    Thanks
    Dave

    Yes it shows up after restart of BIDS .
    But during design time this is a bug I hope Microsoft fixes this bug in the future releases
    Mudassar
    It's not really a bug. Visual Studio loads the environment variables when starting up.
    In future releases you use projects and parameters instead of environment variables, so the issue goes away ;)
    MCSE SQL Server 2012 - Please mark posts as answered where appropriate.

  • Checking for Environment Variable in code

    I need to check to see if an environment variable called "MY_TIME" exists on the system. The value of it does not matter(just use 'none'). I need for windows and unix. I believe they should work the same.
    The java.lang.system.getenv() is deprecated on 1.3.x, 1.4.x but available on 1.5. I'd like to use another way besides the getenv().
    Thanks.
    Something like:
    if( ENVIRONMENT VAIABLE EXISTS ON MY SYSTEM) {
    //do something
    }

    http://www.google.com/search?hl=en&lr=&q=System.getenv
    http://www.javaworld.com/javaworld/javaqa/2001-07/01-q
    a-0706-env.htmlI just read that javaworld article. How wonderful that they throw an error. That is so incredibly stupid. It is also incredibly, moronically stupid that nothing is said about that in the JavaDocs. So, I was wrong in my earlier comment about being able to use getenv() in pre 1.5 JVM's. In general, though, deprecated methods aren't unusable. You just need to take care when using them.
    You may consider using System.exec() to check env variables. Unfortunately that approach requires that you use system-dependent commands, so you'll have to determine which system you are using at runtime.

Maybe you are looking for

  • How to hide  on my iPhone four and iPad mini?

    Every column says just swipe but when I do it on my new iPad it doesn't work! Neither on my iPhone, I'll admit it's jail broken but I don't see how it wouldn't work on my normal iPad I just got yesterday?! Please help!!

  • Re: Problem in SQL Query

    Hi Billy, Thanks for ur reply. It was very helpful. I do have a small problem i want to reterieve a column called doc_class_description from a table called class which also contains the doc_class_code. To be more clear tablename: Class the fields are

  • Item translations are not saved for copied page

    Hello, item translations are not saved for copied page. Is it expected?

  • TWO ipods that are skipping songs

    I am yet to read a definitive answer to this problem: you all know it: my fiancees fifth gen ipod is skipping parts or entire songs... She did not have this problem on the third gen ipod. she ALSO has an ipod shuffle... the songs are now doing the sa

  • Moving thunderbird withEasy Transfer wizard but no Application data in list

    Hi Im using the easy transfer wizard as suggested. I have saved all my old computer files and settings to zip drive. Started the wizard on the new computer hit thr customise button undef my account nsme then the advanced button on he next screen but