wood burning stoves 2.0*
The moose likes Servlets and the fly likes Runtime.exec() IOException Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Runtime.exec() IOException" Watch "Runtime.exec() IOException" New topic

Runtime.exec() IOException

J Hartley
Ranch Hand

Joined: Mar 29, 2001
Posts: 52
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;
Process p = r.exec("dir");
int i;
InputStream os=p.getInputStream();
while((i=os.read()) != -1)
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?
Erick Jones
Ranch Hand

Joined: Jun 17, 2002
Posts: 38
You need to open up a dos shell in order to run a dos command. For example,
Process p = r.exec("cmd /c dir");
Process p = r.exec("command.com /c dir");
Good luck!
I agree. Here's the link: http://aspose.com/file-tools
subject: Runtime.exec() IOException