GeeCON Prague 2014*
The moose likes Linux / UNIX and the fly likes how to use ProcessBuilder for executing a shell script from java? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Engineering » Linux / UNIX
Bookmark "how to use ProcessBuilder for executing a shell script from java?" Watch "how to use ProcessBuilder for executing a shell script from java?" New topic
Author

how to use ProcessBuilder for executing a shell script from java?

Acharya Thiyagarajan
Greenhorn

Joined: Aug 01, 2009
Posts: 18
hi,

I have the below script which i want to execute from java :

ksh -x /lopt/Download.sh -C /lopt/Config.sh 2>ShellscriptError.err

when i tried using exec and when i use waitFor the process is hanging and the thread is a stuck thread. Hence I am trying to use ProcessBuilder. Can anyone please help as to how the syntax should be??? and what are the additional things i should take into consideration so that it doesnt become a stuck thread. All exceptions are handles in the shell script and it exits properly from shell script.

Regards,
Acharya
Stefan Wagner
Ranch Hand

Joined: Jun 02, 2003
Posts: 1923

You can not use redirections with ProcessBuilder, afaik:

Instead you have to open System.err and generate ShellscriptError.err yourself. Together with runtime.exec here is a good explanation: http://www.javaworld.com/javaworld/jw-12-2000/jw-1229-traps.html
Maybe most of the traps are still traps, even when using ProcessBuilder, which is newer than Runtime.exec.


http://home.arcor.de/hirnstrom/bewerbung
 
GeeCON Prague 2014
 
subject: how to use ProcessBuilder for executing a shell script from java?