Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
Acharya Thiyagarajan
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1923
Linux Postgres Database Scala
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic