I am trying to execute command line arguments via Java. For example:
// Execute command
String command = "cmd /c start cmd.exe";
Process child = Runtime.getRuntime().exec(command);
// Get output stream to write from it
OutputStream out = child.getOutputStream();
out.write("cd C:/ /r/n".getBytes());
out.flush();
out.write("dir /r/n".getBytes());
out.close();
The above opens the command line but does not execute cd
or dir
. Any ideas? I am running Windows XP, JRE6.
(I have revised my question to be more specific. The following answers were helpful but do not answer my question.)