Running shell script using runtime.exec() on linux os exits with exitcode 139
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Vishal_Raje
Posted On:   Monday, April 8, 2002 12:24 AM

hi,

i am trying to run a shell script on using Runtime.exec() on linux. The shell script works perfectly if i run it from shell prompt. But while running it using Runtime.exec() process terminates abruptly with exit code 139.



Can anybody help me? Thanks in advance.


Vishal Vishal@india.seipl.com .

Re: Running shell script using runtime.exec() on linux os exits with exitcode 139

Posted By:   Jay_Goodman  
Posted On:   Saturday, April 13, 2002 12:14 AM

When you run a shell script from the shell prompt you are in a/the shell. When you are using Runtime.exec() you are obviously in java, not the shell. With that in mind, part of the fuctionality of your common shells is to read the magic line "#!/bin/ksh" or even "#!/usr/bin/perl". Behind the scenes the shell executes ksh or perl with the script. Java does not read the magic line nor should it. The simplest way is to spawn the program with the shell file

use

String[] apache_start = { "/bin/bash" , "/etc/rc.d/init.d/httpd" , "start" };
String[] vcard= { "/usr/bin/perl" , "/usr/bin/csv2vcard" , "address.csv" , "address.vlist"};

instead of

String[] apache_start = { "/etc/rc.d/init.d/httpd" , "start" };
String[] vcard= { "/usr/bin/csv2vcard" , "address.csv" ,"address.vlist"};


The same concept is why you cannot use pipes and redirections with Runtime.exec()...becuase they are functions of the shell interpreter.
About | Sitemap | Contact