File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
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 EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Runtime.exec() IOException" Watch "Runtime.exec() IOException" New topic
Author

Runtime.exec() IOException

J Hartley
Ranch Hand

Joined: Mar 29, 2001
Posts: 52
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
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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Runtime.exec() IOException
 
Similar Threads
invoking exe from java
unable to run this application
Executing System Commands
Set environment variable of UNIX by java program
Problem in executing shell script using JSP