Results 1 to 5 of 5

Thread: Execute dos command in java

  1. #1
    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.

  2. #2
    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.

  3. #3
    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.

  4. #4
    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.

  5. #5
    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.

Similar Threads

  1. Execute GUI commands from the command line
    By dogonthehorizon in forum Windows Software
    Replies: 1
    Last Post: 21-07-2011, 03:50 AM
  2. How to execute a command without entering path on CentOS 5.5?
    By pREMAsAGAR in forum Operating Systems
    Replies: 5
    Last Post: 07-05-2011, 12:09 PM
  3. Windows phone 7: How to execute the MVVM command?
    By Mishraji in forum Windows Software
    Replies: 3
    Last Post: 27-10-2010, 09:38 PM
  4. How to execute a command in a remote computer?
    By austin26 in forum Technology & Internet
    Replies: 3
    Last Post: 12-12-2009, 08:34 PM
  5. Replies: 1
    Last Post: 08-11-2008, 05:22 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,716,215,516.54579 seconds with 17 queries