Solved

Runtime.exec()

Posted on 2002-05-07
6
335 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
  • 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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
scoresSpecial  challenge 13 42
how to use external config file with Spring MVC 4 63
wordmultiple challenge 12 93
Python Assistance 7 36
Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.

743 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now