Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Tags Active Topics RSS Search Mark Forums Read

Reply
 
Thread Tools Search this Thread
  #1  
Old 22-03-2010
Member
 
Join Date: Mar 2010
Posts: 203
Execute dos command in java

Hello,
I want to run the dos command in my java code. Still now i have done this, but not quite what i am expecting.
Code:
try{
            Runtime.getRuntime().exec("shutdown-a");
           }catch(Exception e){
            System.out.System.out.println("error");
        }
Any more help on this topic will be appreciated. Thanks in advance.
Reply With Quote
  #2  
Old 22-03-2010
Member
 
Join Date: Nov 2009
Posts: 359
Re: Execute dos command in java

Hello,
What is the system running this command?
Linux DIR no
Code:
[ex @ usr ~] DIR $
-bash: DIR: command not found
Is this what you are trying to do in your code, then you should understood that both the operating systems are different and if depends on which operating system you are on. If you are on linux like operating system then this will not work.
Reply With Quote
  #3  
Old 22-03-2010
Member
 
Join Date: Dec 2009
Posts: 202
Re: Execute dos command in java

Hello,
Even I am trying a similar kind of a code and I am also interested in this topic. I am on a Windows machine. I have no idea about the linux operating system. So I want to run different command on a remote machine is Windows 2000. Orders will be to perform basic style "cd", "dir" and executing bash script. So, if you have a solution for this then it would be great and even if you have an alternative method or function for performing the same, then please let me know.
Reply With Quote
  #4  
Old 22-03-2010
Member
 
Join Date: Nov 2009
Posts: 583
Re: Execute dos command in java

Hello,
This is because "dir" sends a response to the output stream. And when you make a Runtime.exec must consume the flow ... (input, output and error) And when the command has several arguments ( 'shutdown' and '-a') must be run through a table. I think this should be pretty easy for you because java provides a good number of api's for the same. Hope you will do the needful.
Reply With Quote
  #5  
Old 22-03-2010
Member
 
Join Date: Mar 2010
Posts: 203
Re: Execute dos command in java

Hello,
Thanks for the replies, they helped me a lot, well I'll see what I can do. For the batch scripts I start counting the direct being positioned in the right directory as if I manually launch. I think this should work fine with the java code, if i am not wrong and if you have any other suggestion for me then please let me know I am then interested one. Also any alternative are appreciated. Thanks in advance.
Reply With Quote
Reply

  TechArena Community > Software > Software Development
Tags: , , , , , ,



Thread Tools Search this Thread
Search this Thread:

Advanced Search


Similar Threads for: "Execute dos command in java"
Thread Thread Starter Forum Replies Last Post
Execute GUI commands from the command line dogonthehorizon Windows Software 1 21-07-2011 03:50 AM
How to execute a command without entering path on CentOS 5.5? pREMAsAGAR Operating Systems 5 07-05-2011 12:09 PM
Windows phone 7: How to execute the MVVM command? Mishraji Windows Software 3 27-10-2010 09:38 PM
How to execute a command in a remote computer? austin26 Technology & Internet 3 12-12-2009 08:34 PM
How to Execute Run Command window in the absence of start menu Howerski Tips & Tweaks 1 08-11-2008 05:22 PM


All times are GMT +5.5. The time now is 04:51 PM.