Running another executable (windows) from within a java program
Hi,
I want to know how to run another executable (windows) from within a java program. I want to execute msinfo32.exe, and run another command of that program.
pwee
Hi,
I want to know how to run another executable (windows) from within a java program. I want to execute msinfo32.exe, and run another command of that program.
pwee
public int exec(String command, StreamGobbler stdout, StreamGobbler stderr) throws IOException, InterruptedException {
try {
Runtimeruntime = Runtime.getRuntime();
Processprocess = runtime.exec(command);
if (stdout != null) {
stdout.setInputStream(process.getInputStream());
stdout.run();
}
if (stderr != null) {
stderr.setInputStream(process.getErrorStream());
stderr.run();
}
intexitValue = runProcess(process);
return exitValue;
} catch(IOException e) {
throw e;
}
}
Something like that.
Morzel
You can also use :-
ProcessBuilder builder = new ProcessBuilder("cmd.exe", "/c", "start notepad.exe");
Process process = builder.start();
Run it in a separate thread to launch more applications.