No backtick shell return value

D

Derek Basch

I have a very simple Perl (1) script that calls a bash shell script (2)
and prints the shell STDOUT.

However, It just hangs forever after the shell script (2) returns. I
cannot figure out what I am doing wrong. Any one have an idea?

Here is the Perl script (1):
------------------------------------------------------------------------
open(COMMAND, "$proxy_dir/proxyctl restart |");
while (my $line=<COMMAND>) {
print $line;
};
close(COMMAND);

print "I won't print";
------------------------------------------------------------------------

Here is the bash shell script:
------------------------------------------------------------------------
#!/bin/bash

THEDIR=/home/proxy/

case "$1" in
start)
echo "Starting $THEDIR proxy"
cd $THEDIR
$THEDIR/proxy2 &
;;
stop)
echo "Shutting down $THEDIR proxy"
PID=`/bin/ps auxwww | /usr/bin/grep "$THEDIR/proxy2 -c
$THEDIR/proxy.conf" | /usr/bin/grep -v grep | awk '{print $2}'`
#echo "PID: $PID"
kill $PID
;;
restart)
$0 stop $THEDIR
$0 start $THEDIR
;;
*)
echo "Usage: $0 {start|stop|restart}"
exit 1
;;
esac
 
J

Joe Smith

Derek said:
However, It just hangs forever after the shell script (2) returns.

perl -le 'print "start";print `sleep 5 & echo OK`'
perl -le 'print "start";print `sleep 5 </dev/null >/dev/null 2>&1 & echo OK`'

The first one waits 5 seconds before printing OK.
The second one prints OK immediately.
-Joe
 
D

Derek Basch

Michele said:
Subject: No backtick shell return value

But you're *not* using backticks below...
However, It just hangs forever after the shell script (2) returns. I
cannot figure out what I am doing wrong. Any one have an idea?

Here is the Perl script (1):

Have you tried testing open() for success as is usually recommended?

Anyway I don't see anything terribly wrong, except that I would use a
lexical filehandle and the three args form of open():

open my $cmd, '-|', "$proxy_dir/proxyctl", 'restart'
or die "Can't run proxyctl: $!\n";

This way you won't fire up a shell, but directly run the script
passing to it the 'restart' cmd line argument.

BTW: (do a favour to yourself and)

use strict;
use warnings;
Here is the bash shell script:
[snip]

I see this is moderately complex. Have you tried using the above with
a script that simply does e.g.

echo 'foo bar baz';

? If it works, then you may have a problem with your shell script, not
with the perl one.


Michele
--
{$_=pack'B8'x25,unpack'A8'x32,$a^=sub{pop^pop}->(map substr
(($a||=join'',map--$|x$_,(unpack'w',unpack'u','G^<R<Y]*YB='
.'KYU;*EVH[.FHF2W+#"\Z*5TI/ER<Z`S(G.DZZ9OX0Z')=~/./g)x2,$_,
256),7,249);s/[^\w,]/ /g;$ \=/^J/?$/:"\r";print,redo}#JAPH,

Shoot. Sorry. My bad. I posted the wrong code. Thanks for the tips
though. I will try them all out and report the results.

Derek
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,819
Latest member
masterdaster

Latest Threads

Top