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
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.