hifake
August 13, 2007, 4:48pm
1
Hi Perl/UNIX experts,
I have a problem in running a shell script from my perl script (auto.pl).
I run the perl script using
perl auto.pl
from the shell prompt
The shell script picks the files in "input" folder and procesess it.
The shell script blue.sh has this code.
export JAVA_HOME=/opt/j2sdk1.4.2_02
export PATH=${JAVA_HOME}/bin:${PATH}
export MANPATH=${JAVA_HOME}/man:${MANPATH}
export RUNPATH=:.:/export/home/lib/activation.jar:/export/home/lib/commons-dbcp-1.1.jar:/export/home/lib/jdbc2_0-stdext.jar:/export/home/lib/libmqjbnd05.so:/export/home/lib/postcard.jar
export RUNPATH=$RUNPATH:/export/home/lib/ant.jar:/export/home/lib/commons-logging-api.jar:/export/home/lib/jms.jar:/export/home/lib/log4j-1.2.8.jar:/export/home/lib/providerutil.jar
export
java -classpath $RUNPATH placeOrders ./input/
I tried to run this in perl script using
exec("blue.sh")
exec("./blue.sh")
`./blue.sh`
`sh blue.sh`
I get this error - ./blue: JAVA_HOME=/opt/j2sdk1.4.2_02: is not an identifier
But if i run it manually from the shell
./blue.sh
the script runs fine.
I guess the problem is because perl spawns a new shell.
porter
August 13, 2007, 5:10pm
2
Have you tried putting
#!/bin/sh
at the start of the script?
hifake
August 13, 2007, 7:13pm
3
Yes. I did that. Still i get the same error.
Moreover, I can't run the shell script manually also.
$ ./blue.sh
./blue.sh: JAVA_HOME=/opt/j2sdk1.4.2_02: is not an identifier
$ sh blue.sh
blue.sh: JAVA_HOME=/opt/j2sdk1.4.2_02: is not an identifier
porter
August 13, 2007, 8:15pm
4
It does not like your exports.
Try
VARIABLE=value
export VARIABLE
hifake
August 14, 2007, 9:46pm
6
kahuna:
Try ksh instead of sh
#!/bin/ksh
Tried this...It does nto help. Still same error.
Any other option? Even if you are more than 50% sure please reply. It doesn't hurt trying.
porter
August 14, 2007, 9:52pm
7
What shell are you running normally?
What is it's complete path?
Try using that in the "#!....." first line.
Then switch to sh, by typing "sh", and then try and run the script.
hifake
August 15, 2007, 2:30am
8
porter:
What shell are you running normally?
What is it's complete path?
Try using that in the "#!....." first line.
Then switch to sh, by typing "sh", and then try and run the script.
It is bash shell.
But when I use "#!..." in the first line, it throws an error...always
Am not able to find the reason.
I tried #!/bin/sh and #!/bin/ksh
It doesn't work. What else do i need to try?
porter
August 15, 2007, 4:59am
9
Hey, it's just a wild guess,...
try
#!/bin/bash
Neo
August 15, 2007, 6:38am
10
Try to exec the shell and pass the name of the script as an argument to the shell (not exec the script directly).
hifake
August 15, 2007, 1:42pm
12
Hi Neo,
Can you tell me how to do this?
Neo
August 15, 2007, 7:46pm
14
Try something like (depending on your shell):
exec("/bin/ksh -c /full/path/to/blue.sh");
...or something like that, depending on the shell, path and syntax.
hifake
August 27, 2007, 2:26pm
15
Hi All,
I tried
`bash blue.sh`
It works. Thanks all for your suggestions.
hifake
August 27, 2007, 2:31pm
16
neo:
Try something like (depending on your shell):
exec("/bin/ksh -c /full/path/to/blue.sh");
...or something like that, depending on the shell, path and syntax.
This works too! Thanks Neo!
I'm encountering a similar problem (but with ksh not sh). Using hifake's original example substituting blue.sh with blue.ksh, I'm wanting to 'dot' in the values, and have them available to the perl process.
ie.
blue.ksh
export JAVA_HOME=/opt/j2sdk1.4.2_02
export PATH=$JAVA_HOME/bin:$PATH
In perl I need to execute the above and be able to run
printf "Value of JAVA_HOME is %s\n", $ENV{JAVA_HOME};
This is similar to running
. ./blue.ksh
At a command prompt, or within a ksh script.
Any Ideas/suggestions?
Thanks...