Win a copy of Escape Velocity: Better Metrics for Agile Teams this week in the Agile and Other Processes forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Tim Cooke
  • Paul Clapham
  • Jeanne Boyarsky
Sheriffs:
  • Ron McLeod
  • Frank Carver
  • Junilu Lacar
Saloon Keepers:
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
Bartenders:
  • Piet Souris
  • Frits Walraven
  • fred rosenberger

problem executing a shell script using Runtime.exec()

 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
I am having trouble executing the following shell script using Runtime.exec()
<code>
#!/bin/ksh
. /sideshow/environment/directories.sh
ROOT=/sideshow/java/scripts/
COMMAND_FILE=${ROOT}commands.IBX.RAW.CRC
cd ${ROOT}
rm -f $COMMAND_FILE
print "Send the command '"$*"' to the inbox"
echo $* >> $COMMAND_FILE
uuencode $COMMAND_FILE `basename $COMMAND_FILE` | mailx <target email address>
</code>
The syntax I use for Runtime.exec is :
<code>
String cmd[] =
{"/bin/ksh",
"-c",
"/sideshow/java/scripts/send.command.sh"};
Process p = Runtime.getRuntime().exec (cmd);
try { p.waitFor(); } catch (Exception e) {e.printStackTrace();}
</code>
The error I am recieving from the output is:
<code>
send.command.sh[2]: basename: not found.
send.command.sh[21]: rm: not found.
send.command.sh[26]: basename: not found.
send.command.sh[26]: mailx: not found.
send.command.sh[26]: uuencode: not found.
</code>
This script work fine from a UNIX command line but doesn't work using Runtime.exec(). Any help is greatly appreciated.
Thanks
John
 
High Plains Drifter
Posts: 7289
Netbeans IDE VI Editor
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
We were talking about this a while ago in the Linux/Unix forum. I believe we decided the most common problem is in not setting the execute bit of the script. Do you have that set?
------------------
Michael Ernest, co-author of: The Complete Java 2 Certification Study Guide
 
Sgt. John Seifert
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
actually I solved the problem.
for the benifit of others,
the solution i came up with was to specify the full path to the script variables that it could not find.
for example: it could not find 'basename'
so in my script i replaced 'basename' with 'usr/bin/basename'
what happens is that sometimes the environment is not loaded as it should be so paths to these special reserved functions can not be found, therefore specifying the full path will correct the problem.
hope this can help others, this one was a real pain
 
Sgt. John Seifert
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
fyi,
the path can be found at a unix prompt by typing
which basename
or
which <whatever you are trying to find.>
 
My previous laptop never exploded like that. Read this tiny ad while I sweep up the shards.
Garden Master Course kickstarter
https://coderanch.com/t/754577/Garden-Master-kickstarter
reply
    Bookmark Topic Watch Topic
  • New Topic