| | |
Need help to run Command Prompt from java program
![]() |
•
•
Join Date: Jun 2005
Posts: 18
Reputation:
Solved Threads: 0
Hi,
I want to start the command prompt window from my java program.
Tried using Runtime but its not working.These are my codes :
String command = "cmd.exe";
try {
child = Runtime.getRuntime().exec(command);
}
catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
Actually, its working when i change the value of command, like ita working when i put "notepad.exe". May be i m using a wrong command for cmd prompt. If anyone can figure it out, then i will be really thankful.
I want to start the command prompt window from my java program.
Tried using Runtime but its not working.These are my codes :
String command = "cmd.exe";
try {
child = Runtime.getRuntime().exec(command);
}
catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
Actually, its working when i change the value of command, like ita working when i put "notepad.exe". May be i m using a wrong command for cmd prompt. If anyone can figure it out, then i will be really thankful.
Not sure if this will work, but the command for opening the cmd shell in a batch file is simply cmd. Maybe try changing the line
to simply
and see what happens?
EDIT: Actually, if that doesn't work, try "start" instead of "cmd" as that is the command to open a new CMD shell from a running CMD shell.
java Syntax (Toggle Plain Text)
String command = "cmd.exe";
java Syntax (Toggle Plain Text)
String command = "cmd";
EDIT: Actually, if that doesn't work, try "start" instead of "cmd" as that is the command to open a new CMD shell from a running CMD shell.
Last edited by darkagn; Oct 22nd, 2008 at 6:47 am. Reason: Found more info...
There are no stupid questions, only those too stupid to ask for help.
echo is a web developer's best friend. It might also be worthwhile pointing out that this code will only work on windows operating systems. Really you should probably have this in an if-statement to ensure running this code only in a windows environment. An else statement might allow you to open a different shell in Linux, Mac, other environments?
There are no stupid questions, only those too stupid to ask for help.
echo is a web developer's best friend. ![]() |
Similar Threads
- How to run a *.exe file in Java (Java)
- put the Dos 's command into java program? (Java)
- Exception in thread "main" java.lang.NoClassDefFoundError: Invaders Error (Java)
- How to run c++ program through command prompt? (C++)
- Running Java Program outside an IDE (Java)
- java.lang.NoSuchMethodError: (Java)
Other Threads in the Java Forum
- Previous Thread: Updating JAR applications
- Next Thread: Illegal escape character Error
| Thread Tools | Search this Thread |
-xlint add android api applet application array arrays automation bi binary blackberry block bluetooth class client code compile compiler component database developmenthelp eclipse equation error event fractal freeze functiontesting game gameprogramming givemetehcodez graphics gui health html hyper ide image int integer j2me j2seprojects java javac javaprojects jetbrains jni jpanel jtable julia learningresources lego linux list login loops mac main map method methods mobile myregfun netbeans nonstatic notdisplaying number online pearl problem program programming project qt recursion scanner screen server set singleton sms sort spamblocker sql string swing system textfields thread threads time title tree tutorial-sample update variablebinding windows working xor






(