Need help to run Command Prompt from java program

Reply

Join Date: Apr 2006
Posts: 164
Reputation: orko is an unknown quantity at this point 
Solved Threads: 10
orko orko is offline Offline
Junior Poster

Re: Need help to run Command Prompt from java program

 
0
  #11
Oct 22nd, 2008
I don't know the exact solution. I may try once I go home. Just few suggestions:
1. Since Java 1.5 a new class ProcessBuilder has been introduced to replace exec(). So might be a good idea to try with ProcessBuilder and see if it works.
2. A work around can be to take user input, execute it, and display it. Might be a lot of work. You may find this useful: http://forums.sun.com/thread.jspa?th...sageID=4351862
A Perfect World
Reply With Quote Quick reply to this message  
Join Date: Oct 2008
Posts: 26
Reputation: babusek is an unknown quantity at this point 
Solved Threads: 1
babusek babusek is offline Offline
Light Poster

Re: Need help to run Command Prompt from java program

 
0
  #12
Oct 23rd, 2008
Hi manisha ,

I tried the same above but it's not opening the command prompt ,
it's compiled successfully , but it is hanging after that ,

sekharbabuk@sekharbabuk /cygdrive/c/j2sdk1.4.2_16/bin
$ javac RunUnixCommand.java

sekharbabuk@sekharbabuk /cygdrive/c/j2sdk1.4.2_16/bin
$ java RunUnixCommand
-----------###------------------------------------------
 Command = cmd.exe
--------------------------------------------------------
 File Found : Microsoft Windows XP [Version 5.1.2600]
 File Found : (C) Copyright 1985-2001 Microsoft Corp.
 File Found :

i tried this using cygwin environment in windows operating system..
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
  #13
Oct 23rd, 2008
thanks Orko,
but ProcessBuilder does the same. My problem is that in the end i need a command prompt window to open.Its working when i change the command from "cmd" to"notepad.exe". Its working then.I am really unable to figure out the problem.Anyways thanx for making an effort to help
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
  #14
Oct 23rd, 2008
Sorry i dont have any idea about cygwin env


Originally Posted by babusek View Post
Hi manisha ,

I tried the same above but it's not opening the command prompt ,
it's compiled successfully , but it is hanging after that ,




i tried this using cygwin environment in windows operating system..
Reply With Quote Quick reply to this message  
Join Date: Oct 2008
Posts: 26
Reputation: babusek is an unknown quantity at this point 
Solved Threads: 1
babusek babusek is offline Offline
Light Poster

Re: Need help to run Command Prompt from java program

 
0
  #15
Oct 23rd, 2008
ok, if u you know the answer please post here..
Reply With Quote Quick reply to this message  
Join Date: Feb 2009
Posts: 1
Reputation: alinutza200483 is an unknown quantity at this point 
Solved Threads: 0
alinutza200483 alinutza200483 is offline Offline
Newbie Poster

Re: Need help to run Command Prompt from java program

 
0
  #16
Feb 26th, 2009
I think it's "a bit" late, but... for anyone still "listening"...

String[] command = { "cmd.exe", "/C", "Start"};
Runtime.getRuntime().exec(command);

Works for me. Hope it helps.
Reply With Quote Quick reply to this message  
Join Date: May 2008
Posts: 128
Reputation: PhiberOptik is an unknown quantity at this point 
Solved Threads: 4
PhiberOptik's Avatar
PhiberOptik PhiberOptik is offline Offline
Junior Poster

Re: Need help to run Command Prompt from java program

 
0
  #17
Feb 26th, 2009
Hi Manisha,
I tried the exact same thing you are attempting to do. I found that it is possible but very difficult (I never did it) I found the best way is to just launch cmd with arguments.
History will be kind to me for I intend to write it.
---------------------------------- Sir Winston Churchill
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