Click to See Complete Forum and Search --> : perl return codes
crokett
04-05-2001, 10:07 PM
does perl return any values after a script is finished? if the following is in a shell script, would it work?
if (perl somescript.pl)
then
do something
else
do some other thing
fi
thanks
Well, I know jack-doo about shell scripting and I've never deliberately returned any values from a perl script, but I threw the following two things together, and calling
prompt$ test.bash 0
causes it to say hello, while calling
prompt$ test.bash 1
causes it to say goodbye. The return values are the opposite of what I'd expect, but I'm sure that's because there's something that I don't know about bash.
test.bash:
#!/usr/bin/bash
if (./test.pl $1)
then
echo Hello!
else
echo Goodbye!
fi
test.pl
#!/usr/local/bin/perl
print "this is a test\n";
exit @ARGV[0];
YaRness
04-06-2001, 07:59 AM
someone on a 'nix system just try
#!/usr/local/bin/perl
1
or "0", with the same type of bash script above, and see if it behaves like you'd think it would (prolly some benefit in ending a script with just "1" than "exit 1", though right now all i can think is that the exit command may just be unnecessary). i can't seem to figure out or remember which perl man page talks about this stuff. though reading up on the exit function in perlfunc (which also says to read up on the perlmod for a few more details) would definitely be a good idea.
Stuka
04-06-2001, 10:27 AM
kmj-
The reason the results seem weird is due to old convention. Unlike C (and most programming languages I can think of), most OS's treat a program returning an exit code of 0 as normal, where a non-zero return code is abnormal.
crokett
04-06-2001, 01:40 PM
i got back to a linux box today and wrote the following perl scripts:
test1.pl
perl test2.pl;
test2.pl
print "This is test2\n";
i wrote shell script:
if (perl test1.pl)
then
echo "success"
else
echo "Failure"
fi
after running the shell script with test2.pl there, the script echoed "succss". when i renamed test2, it echoed "failure". it looks like perl will return a false if it fails to execute a script.
Makes sense (a reply to both Stuka's and Crockett's posts. :) )