michbach has asked for the wisdom of the Perl Monks concerning the following question:

Hi all, i have an exe-program, it produce permantly an output on stdout. Now i want to write a perl-program that running parallel and catch the return-code from the exe-program and do anything with that value. I guess im on the right way with open and pipe but it dont run good. I tried with two perl-programs. A.pl produce the permanently the output and B.pl try to catch the output on stdout and work with that return code (see the code). But if i take a higher sleep-value (may be 1 second) in A.pl and i start B.pl then B.pl is hanging...
#XXXXXXXXXXXXXXXXX Code von A.pl XXXXXXXXXXXXXXXXX use Time::HiRes qw(sleep); $out = 1; while(1==1) { #### delay #sleep 1; dont work sleep 0.001; #### write to output to stdout print "\n$out"; $out++; #### start on 0 again if($out > 50){$out = 1;} } #XXXXXXXXXXXXXXXXX Code von B.pl XXXXXXXXXXXXXXXXX open(FH, "c:\\A.pl |") or die "Open-Fehler...\n"; while($tmp=<FH>) { chomp($tmp); #### proof the output from A.pl if($tmp eq 25){print "\nTreffer";} print "\n$tmp"; } close (FH);
Programm B.pl should start Programm A and then always proof what A.pl is writing to stdout and then do anything .... Many thanks and best regards, michbach PS: i use Windows-XP

Replies are listed 'Best First'.
Re: use the return code of another program
by ikegami (Patriarch) on Mar 28, 2009 at 01:08 UTC
      First, thanks a lot to all responsers!!! $| = 1; in A.pl has fixed that problem.. Best regard to all, michbach
Re: use the return code of another program
by sflitman (Hermit) on Mar 28, 2009 at 05:00 UTC
    I found this to be something I do often, I posted some code which might be helpful for you here. Reuse and conquer!

    HTH,
    SSF