I am running windows 2000, and i have having some problems running this code. It work when for exec("ping"), or exec("ftp") but trying to run exec("dir") or exec("set") it breaks. Can anyone help??? I am guessing that i need to give
java more rights to run system commands or something??? Thank you for any help...
import java.io.*;
public class RunOSCommand {
public RunOSCommand() {
}
public static void main(
String[] args) {
System.out.println("in the main");
try
{
Runtime r = Runtime.getRuntime();
String cmd = ("set");
Process p = r.exec(cmd);
BufferedReader reader = new BufferedReader(new InputStreamReader(new
DataInputStream( new BufferedInputStream(p.getInputStream()))));
String lineRead =null;
while( (lineRead = reader.readLine() ) != null)
{
System.out.println(lineRead);
}
}
catch(Exception e)
{
e.printStackTrace();
}
}
}
// --------------------------------------------------------
H:\java>java RunOSCommand
in the main
java.io.IOException: CreateProcess: set error=2
at java.lang.Win32Process.create(Native Method)
at java.lang.Win32Process.<init>(Win32Process.java:64)
at java.lang.Runtime.execInternal(Native Method)
at java.lang.Runtime.exec(Runtime.java:300)
at java.lang.Runtime.exec(Runtime.java:247)
at RunOSCommand.main(RunOSCommand.java, Compiled Code)