in reply to system() not waiting

system() forks a child to run the program via an exec and is supposed to wait for the child to finish. Assuming what you say is actually the problem (not the typo noted above):

I would suspect that the redirection to $temp$file is the problem with the system call returning while the shell is doing the write producing a race condition which perl is winning. Have you tried adding a say sleep 1; after the first system call to see if this fixes the problem?

To ensure that the first call has finished you could call it with backticks and capture the output. Then use perl to write $temp$file.

$data = `/3rdparty/perl/bin/sunos5/lwp-request -p http://proxy-syr.glo +bal.lmco.com $hostname$url -C $user:$password`; open F, ">$temp$file" or die "Can't write $temp$file, $1\n"; print F $data; close F; # you don't need the system call to do chmod as Perl has one chmod 777, $tempfile or die "Can't chmod $temp$file $!\n"; system("acroread -toPostScript $temp$file"); system("lp -d ep5_hpp01 $temp *.ps");

If none of that works you could resort to implementing the whole thing in pure Perl.

tachyon

s&&rsenoyhcatreve&&&s&n.+t&"$'$`$\"$\&"&ee&&y&srve&&d&&print

Replies are listed 'Best First'.
Re: Re: Wait
by bluto (Curate) on Oct 03, 2001 at 20:18 UTC
    The shell doesn't do any writing here. It merely redirects STDOUT to point to the file and then fork/execs the new process. Backticks won't do anything more than system() here either -- it won't ensure you get all of the output. If the system'd process forks itself into the background, backticks (like system) will return immediately and stop grabbing output at that point.

    You need to find out which process is not waiting (lwp-request?) and either stop it from doing that or reimplement that part only in perl. (gbarr's suggestion to check for '&' is a good start.)

    bluto