Need help to run Command Prompt from java program

Reply

Join Date: Jun 2005
Posts: 18
Reputation: manisha is an unknown quantity at this point 
Solved Threads: 0
manisha manisha is offline Offline
Newbie Poster

Need help to run Command Prompt from java program

 
0
  #1
Oct 22nd, 2008
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.
Reply With Quote Quick reply to this message  
Join Date: Aug 2007
Posts: 790
Reputation: darkagn has a spectacular aura about darkagn has a spectacular aura about darkagn has a spectacular aura about 
Solved Threads: 109
darkagn's Avatar
darkagn darkagn is offline Offline
Master Poster

Re: Need help to run Command Prompt from java program

 
0
  #2
Oct 22nd, 2008
When you say it's not working, do you get an error message?
There are no stupid questions, only those too stupid to ask for help.
echo is a web developer's best friend.
Reply With Quote Quick reply to this message  
Join Date: Jun 2005
Posts: 18
Reputation: manisha is an unknown quantity at this point 
Solved Threads: 0
manisha manisha is offline Offline
Newbie Poster

Re: Need help to run Command Prompt from java program

 
0
  #3
Oct 22nd, 2008
no i am not getting any error message. All other parts of the program are working well.Just at the end the command prompt is supposed to open.but it isnt doing so (
Reply With Quote Quick reply to this message  
Join Date: Aug 2007
Posts: 790
Reputation: darkagn has a spectacular aura about darkagn has a spectacular aura about darkagn has a spectacular aura about 
Solved Threads: 109
darkagn's Avatar
darkagn darkagn is offline Offline
Master Poster

Re: Need help to run Command Prompt from java program

 
0
  #4
Oct 22nd, 2008
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
  1. String command = "cmd.exe";
to simply
  1. String command = "cmd";
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.
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.
Reply With Quote Quick reply to this message  
Join Date: Aug 2007
Posts: 790
Reputation: darkagn has a spectacular aura about darkagn has a spectacular aura about darkagn has a spectacular aura about 
Solved Threads: 109
darkagn's Avatar
darkagn darkagn is offline Offline
Master Poster

Re: Need help to run Command Prompt from java program

 
0
  #5
Oct 22nd, 2008
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.
Reply With Quote Quick reply to this message  
Join Date: Jun 2005
Posts: 18
Reputation: manisha is an unknown quantity at this point 
Solved Threads: 0
manisha manisha is offline Offline
Newbie Poster

Re: Need help to run Command Prompt from java program

 
0
  #6
Oct 22nd, 2008
Thanks,
Actually i did try "cmd" , and it was all the same. But i m trying again , will tell u the result.
Reply With Quote Quick reply to this message  
Join Date: Jun 2005
Posts: 18
Reputation: manisha is an unknown quantity at this point 
Solved Threads: 0
manisha manisha is offline Offline
Newbie Poster

Re: Need help to run Command Prompt from java program

 
0
  #7
Oct 22nd, 2008
hey dear, its not working.
i tried using "start" but its showing error

java.io.IOException: Cannot run program "start": CreateProcess error=2,
Reply With Quote Quick reply to this message  
Join Date: Jun 2005
Posts: 18
Reputation: manisha is an unknown quantity at this point 
Solved Threads: 0
manisha manisha is offline Offline
Newbie Poster

Re: Need help to run Command Prompt from java program

 
0
  #8
Oct 22nd, 2008
I am using Windows. But i am doing everything in Eclipse.Hope that doesnt make any difference.
Reply With Quote Quick reply to this message  
Join Date: Aug 2007
Posts: 790
Reputation: darkagn has a spectacular aura about darkagn has a spectacular aura about darkagn has a spectacular aura about 
Solved Threads: 109
darkagn's Avatar
darkagn darkagn is offline Offline
Master Poster

Re: Need help to run Command Prompt from java program

 
0
  #9
Oct 22nd, 2008
Sorry manisha but I am out of ideas. Maybe someone else can help you?
There are no stupid questions, only those too stupid to ask for help.
echo is a web developer's best friend.
Reply With Quote Quick reply to this message  
Join Date: Jun 2005
Posts: 18
Reputation: manisha is an unknown quantity at this point 
Solved Threads: 0
manisha manisha is offline Offline
Newbie Poster

Re: Need help to run Command Prompt from java program

 
0
  #10
Oct 22nd, 2008
its ok, thanx a lot for making an effort
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC