It's not a secret anymore!
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
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 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(( != -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(" /c dir");
Good luck!
I agree. Here's the link:
subject: Runtime.exec() IOException
It's not a secret anymore!