Problem using Runtime.getRuntime().exec() setting working directory
807603Jan 31 2008 — edited Jan 31 2008hi
I'm writing an application for win32 which has to execute a batchfile (deploy.bat).
This batch file copy my application process result as content file in a specific path and send a mail notification with Blat (win32 command line utility, www.blat.net).
My application doesn't work fine (OS:Windows Server 2003, jvm: 1.6) if I use Runtime.getRuntime().exec() setting working directory. My tests in the following java code:
1.
String[] args = new String[3];
args[0] = "cmd.exe";
args[1] = "/C";
args[2] = "deploy.bat";
Process proc = Runtime.getRuntime().exec(args);
int rc = proc.waitFor();
return rc;
2.
String[] args = new String[3];
args[0] = "cmd.exe";
args[1] = "/C";
args[2] = "deploy.bat";
String envp[] = new String[n];
envp[0] = ENV_VAR_1 + "=" + var_1;
[...]
envp[n] = ENV_VAR_n + "=" + var_n;
String scriptsdir = "C:/workspace"
File dir = new File(scriptsDir);
Process proc = Runtime.getRuntime().exec(args, envp, dir);
int rc = proc.waitFor();
return rc;
If I execute the first option it works fine, but it is not what I need.
Second option execution fails whitout exception and the Blat Log shows a socket error.
Can anyone help me?