Solved

Runtime.exec()

Posted on 2002-05-07
6
348 Views
Last Modified: 2010-03-31
Process p = Runtime.getRuntime().exec("dir");

Why does the above sentence throw the following error ?

java.io.IOException: CreateProcess: dir error=2

How do we use Runtime.getRuntime().exec() to execute DOS commands ?

Please help
0
Comment
Question by:sekharj
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
6 Comments
 
LVL 3

Expert Comment

by:daitt
ID: 6993768
because dir is a DOS command, you need a command intepreter to run it.
Usually, you run it with "command /c dir"
0
 

Author Comment

by:sekharj
ID: 6993848
daitt,

Process p = Runtime.getRuntime().exec("command /c dir");
System.out.println(p.exitValue());

Those are the lines I used. I still get the error :

java.io.IOException: CreateProcess: command /c dir error=2
0
 
LVL 3

Accepted Solution

by:
daitt earned 100 total points
ID: 6994089
yeah the file is command.com .. it's somewhere in your system. THIs is an example that works on my system:

Process p = Runtime.getRuntime().exec("c:\\windows\\system32\\command.com /c dir");
p.waitFor();
System.out.println(p.exitValue());
0
 
LVL 3

Expert Comment

by:daitt
ID: 7015395
Does it answer your question, sekhari?
0
 
LVL 35

Expert Comment

by:girionis
ID: 8709879
No comment has been added lately, so it's time to clean up this TA.

I will leave a recommendation in the Cleanup topic area that this question is:

- points to daitt

Please leave any comments here within the
next seven days.

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER !

girionis
Cleanup Volunteer
0

Featured Post

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
How to determine if a string is a valid SHA value 7 43
jboss 7.1 start up error 1 60
Java Restore security prompts not working 10 123
jsp error 6 43
Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
The viewer will learn how to implement Singleton Design Pattern in Java.

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question