eweaverp has asked for the wisdom of the Perl Monks concerning the following question:
Hola Monks...
I have some code like this:
which checks via 'ps' to see if the spawned sFTP process has ended--that is, the grep count of its PID is 0--before moving on (the space is to make sure '1134' doesn't match '11134', etc.). I have two questions:my $pid = open(SFTP, '|-', "sftp $hostname > /tmp/_sftplog.txt"); print SFTP "some commands"; close (SFTP); my $pidflag; do { system('sleep 5'); $pidflag = `ps -a \| grep -c \' $pid \'`; chomp($pidflag); } while ($pidflag);
1) Is this even necessary? Does close() guarantee the process has finished?
2) Is there a less kludgy way to do this? My method seems very crude. I poked around at the $? variable, but it doesn't seem to give me what I want.
Thanks,
~evan
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Waiting for an external process to end?
by ctilmes (Vicar) on Jul 24, 2003 at 21:08 UTC | |
|
Re: Waiting for an external process to end?
by Anonymous Monk on Jul 24, 2003 at 22:43 UTC | |
by eweaverp (Scribe) on Jul 25, 2003 at 19:38 UTC |