• Post Reply Bookmark Topic Watch Topic
  • New Topic

Trying to execute a cmd command using Runtime.getRuntime().exec  RSS feed

 
Nikolas Nikolaou
Ranch Hand
Posts: 101
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi.I'm trying to run a ping command but all I manage to do Is open a new cmd window.I'm not sure how to add the ping command to the String[].

 
Stan Giggs
Greenhorn
Posts: 4
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
"exec" method takes String[] as a parameter. This parameter should contain a command and it's arguments.
In your case it should be:

If you execute the code below, you will be able to see output of the command in the console:

Hope this helps.
 
Nikolas Nikolaou
Ranch Hand
Posts: 101
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for that.It works and I'll use It!
Is there any way to open a cmd with a ping command without getting an inputstream and printing It out Just like typing "ping localhost" from a run box ?
 
Tony Docherty
Bartender
Posts: 3271
82
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You could use something like:
But the window will only remain open whilst ping is running.
 
Nikolas Nikolaou
Ranch Hand
Posts: 101
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks! All Is well now!
 
Campbell Ritchie
Marshal
Posts: 56518
172
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Never go anywhere near Runtime.exec() until you have read and understood the classic article by Michael Daconta.
 
Nikolas Nikolaou
Ranch Hand
Posts: 101
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ok,I'll go there but It sounds scary!
 
Campbell Ritchie
Marshal
Posts: 56518
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The article might be scary, but the things which go wrong with Runtime.exec() if you use it wrongly are scarier.
 
Nikolas Nikolaou
Ranch Hand
Posts: 101
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
agreed.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!