I tried the sample code and got an IOException. Can anybody figure out what's the problem with the code?
I am using windows millenium platform.
The code is as follows:
package javaUtilities;
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 = "dir";
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();
}
}
}
java.io.IOException: CreateProcess: dir error=0
at java.lang.Win32Process.create(Native Method)
at java.lang.Win32Process.<init>(Win32Process.java:66)
at java.lang.Runtime.execInternal(Native Method)
at java.lang.Runtime.exec(Runtime.java:551)
at java.lang.Runtime.exec(Runtime.java:418)
at java.lang.Runtime.exec(Runtime.java:361)
at java.lang.Runtime.exec(Runtime.java:325)
at javaUtilities.RunOSCommand.main(RunOSCommand.java:26)