Win a copy of Escape Velocity: Better Metrics for Agile Teams this week in the Agile and Other Processes forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Tim Cooke
  • Paul Clapham
  • Jeanne Boyarsky
Sheriffs:
  • Ron McLeod
  • Frank Carver
  • Junilu Lacar
Saloon Keepers:
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
Bartenders:
  • Piet Souris
  • Frits Walraven
  • fred rosenberger

Runtime.exec() IOException

 
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
You've gotta fight it! Don't give in! Read this tiny ad:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic