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

[183 byte] By [pweea] at [2007-11-27 10:27:58]
# 1

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

Morzela at 2007-7-28 17:49:00 > top of Java-index,Java Essentials,New To Java...
# 2

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.

Brucesworda at 2007-7-28 17:49:00 > top of Java-index,Java Essentials,New To Java...