To set the working directory of a process you start with Runtime.exec, use the version that takes File as one of the parameters.
The working directory is private to the process, it cannot be changed by running a "cd" command in a different process.
Question
This is the code I use:
Runtime runtime = Runtime.getRuntime();
Process process = runtime.exec("cmd /C cd C:/Users/ASUS/Desktop/semantics/semantics/bin");
process = runtime.exec("java test \"abc\" \"def\"");
InputStream is = process.getInputStream();
InputStreamReader isr = new InputStreamReader(is);
BufferedReader br = new BufferedReader(isr);
String line = "", tmp;
while ((tmp = br.readLine()) != null) {
line += tmp;
}
System.out.println(line);
I tried to use commands such as "cmd /C dir" and i got a proper return value.
And this is my test application :
import semantics.Compare;
public class USAGE {
public static void main(String[] args) {
String a = args[0];
String b = args[1];
Compare c = new Compare(a,b);
System.out.println(c.getResult());
}
}
Solution
To set the working directory of a process you start with Runtime.exec, use the version that takes File as one of the parameters.
The working directory is private to the process, it cannot be changed by running a "cd" command in a different process.