| Author |
trying to run a linux commands from a java app
|
sribu sribu
Greenhorn
Joined: May 02, 2006
Posts: 2
|
|
Hi, I am trying to run a linux commands from a java app.The below code works for executing windows commands in java application,but how can i do in Linux. Please help me it very urgent. Thanks, try { String osName = System.getProperty("os.name" ); System.out.println(" OS NAME is "+osName); // String[] cmd = new String[3]; if( osName.equals( "Windows 2000" ) ) { cmd[0] = "cmd.exe" ; cmd[1] = "/C" ; cmd[2] = args; } Runtime rt = Runtime.getRuntime(); System.out.println("Execing " + cmd[0] + " " + cmd[1] + " " + cmd[2]); Process proc = rt.exec(); // any error message?
|
 |
Stefan Wagner
Ranch Hand
Joined: Jun 02, 2003
Posts: 1923
|
|
Well - that depends on the command to run of course. I.e.: run it like that: btw.: OS NAME is Linux [ May 03, 2006: Message edited by: Stefan Wagner ]
|
http://home.arcor.de/hirnstrom/bewerbung
|
 |
Ernest Friedman-Hill
author and iconoclast
Marshal
Joined: Jul 08, 2003
Posts: 24045
|
|
The equivalent of "cmd /c" is "sh -c". A command line like sh -c "foo > outputfile < inputfile" lets that last argument be interpreted by the shell as if it were typed at the shell prompt.
|
[Jess in Action][AskingGoodQuestions]
|
 |
 |
|
|
subject: trying to run a linux commands from a java app
|
|
|