Hi, I have got a piece of code that runs the NT "dir" command and prints the results. It works fine when run in a standalone class. When I run it in a Servlet, I get java.io.IOException: CreateProcess: dir error=2 at java.lang.Win32Process.create(Native Method) Here is the code... Runtime r=Runtime.getRuntime(); //Process p=null; //p=r.exec("dir"); Process p = r.exec("dir"); int i; InputStream os=p.getInputStream(); while((i=os.read()) != -1) System.out.println((char)i); System.out.println("<br><b> Script Process ID :"+p+"</b><br>");
I am running in the Tomcat container. Anyone know how I can resolve this? Thanks, Joe
Erick Jones
Ranch Hand
Joined: Jun 17, 2002
Posts: 38
posted
0
You need to open up a dos shell in order to run a dos command. For example, Process p = r.exec("cmd /c dir"); OR Process p = r.exec("command.com /c dir"); Good luck! Erick