TechArena Community

TechArena Community (http://forums.techarena.in/)
-   Software Development (http://forums.techarena.in/software-development/)
-   -   Execute dos command in java (http://forums.techarena.in/software-development/1318615.htm)

Gillian Anderson 22-03-2010 01:13 PM

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.

NetworkeR 22-03-2010 01:15 PM

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.

ISAIAH 22-03-2010 01:18 PM

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.

SoftWore 22-03-2010 01:19 PM

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.

Gillian Anderson 22-03-2010 01:21 PM

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.


All times are GMT +5.5. The time now is 12:25 AM.