Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to open command prompt from a java program

 
preddy Narra
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

How to open command prompt from a java program..

please give me the code..

PC
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Have a read of the JavaDocs for Runtime.exec. Also, have a search through this forum for references to Runtime.exec. You should find plenty example code.
 
Naseem Khan
Ranch Hand
Posts: 809
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well I tried but none of line 1, 2 or 3 starts a command prompt. I think from command prompt, I am running this program, so thats why it won't start a new process.



Naseem
 
Joe Ess
Bartender
Posts: 9279
10
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What happens if you type those commands into a prompt? Do they open a new command prompt?
 
Naseem Khan
Ranch Hand
Posts: 809
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It does nothing. With the above code it does not open a new command prompt.
[ July 11, 2006: Message edited by: Naseem Khan ]
 
Joe Ess
Bartender
Posts: 9279
10
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Right. So the problem isn't with Java, it's with your use of the command line. First you should set out to discover what command will create a new window. A simple web search led me to this handy reference. Once you have the command, you'll still need a command interpreter to run it, so your exec line should include a call to it. Let us know what you try and if you are still stumped.
 
Naseem Khan
Ranch Hand
Posts: 809
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Joe,

With your reference and little r&d, it worked.

Code below:



Thanks
[ August 06, 2006: Message edited by: Naseem Khan ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic