J
Justin
Hi all,
I've inherited a rather scrappy setup whereby a perl script calls a 2nd
script with system() (which writes to STDOUT) which then exec's a command
(which also writes to STDOUT). Under v5.8.0 I lose the STDOUT (and
STDERR) from the second script onwards. Under our legacy v5.002 it works
as I would hope.
e.g. I have 3 scripts, stage1, stage2, stage3. I run stage1 from the
console, which calls stage2 with system(), which calls stage3 with exec.
-----------------stage1------------------
#!/usr/local/bin/perl
select STDOUT; $|=1; #autoflush STDOUT
print STDOUT "Stage 1 STDOUT\n";
print STDERR "Stage 1 STDERR\n";
#Now call Stage 2 with system() which forks, then retuns
print "Calling (system) Stage 2 from Stage 1...\n";
system("stage2");
print "Returned from Stage 2 to Stage 1\n";
------------------stage2-----------------
#!/usr/local/bin/perl
select STDOUT; $|=1; #autoflush STDOUT
print STDOUT "Stage 2 STDOUT\n";
print STDERR "Stage 2 STDERR\n";
#Now call Stage 3 with system() which forks, then retuns
print "Calling (via exec) Stage 3 from Stage 2...\n";
exec("stage3");
print "Returned from Stage 3 to Stage 2\n";
-------------------stage3----------------
#!/usr/local/bin/perl
select STDOUT; $|=1; #autoflush STDOUT
print STDOUT "Stage 3 STDOUT\n";
print STDERR "Stage 3 STDERR\n";
I run the commands from the console so I see STDOUT and STDERR. Under
Perl v5.002 I get the STDOUT (and STDERR) from all 3 stages displayed:
Stage 1 STDOUT
Stage 1 STDERR
Calling (system) Stage 2 from Stage 1...
Stage 2 STDOUT
Stage 2 STDERR
Calling (via exec) Stage 3 from Stage 2...
Stage 3 STDOUT
Stage 3 STDERR
Returned from Stage 2 to Stage 1
Under Perl v5.8.0 I get the following:
Stage 1 STDOUT
Stage 1 STDERR
Calling (system) Stage 2 from Stage 1...
Returned from Stage 2 to Stage 1
Now I want it to work like v5.002. You can see I've tried autoflush.
According to Perlfaq8, "With system(), both STDOUT and STDERR will go the
same place as the script's versions of these, unless the command
redirects them."
Any ideas?
Cheers,
Justin
I've inherited a rather scrappy setup whereby a perl script calls a 2nd
script with system() (which writes to STDOUT) which then exec's a command
(which also writes to STDOUT). Under v5.8.0 I lose the STDOUT (and
STDERR) from the second script onwards. Under our legacy v5.002 it works
as I would hope.
e.g. I have 3 scripts, stage1, stage2, stage3. I run stage1 from the
console, which calls stage2 with system(), which calls stage3 with exec.
-----------------stage1------------------
#!/usr/local/bin/perl
select STDOUT; $|=1; #autoflush STDOUT
print STDOUT "Stage 1 STDOUT\n";
print STDERR "Stage 1 STDERR\n";
#Now call Stage 2 with system() which forks, then retuns
print "Calling (system) Stage 2 from Stage 1...\n";
system("stage2");
print "Returned from Stage 2 to Stage 1\n";
------------------stage2-----------------
#!/usr/local/bin/perl
select STDOUT; $|=1; #autoflush STDOUT
print STDOUT "Stage 2 STDOUT\n";
print STDERR "Stage 2 STDERR\n";
#Now call Stage 3 with system() which forks, then retuns
print "Calling (via exec) Stage 3 from Stage 2...\n";
exec("stage3");
print "Returned from Stage 3 to Stage 2\n";
-------------------stage3----------------
#!/usr/local/bin/perl
select STDOUT; $|=1; #autoflush STDOUT
print STDOUT "Stage 3 STDOUT\n";
print STDERR "Stage 3 STDERR\n";
I run the commands from the console so I see STDOUT and STDERR. Under
Perl v5.002 I get the STDOUT (and STDERR) from all 3 stages displayed:
Stage 1 STDOUT
Stage 1 STDERR
Calling (system) Stage 2 from Stage 1...
Stage 2 STDOUT
Stage 2 STDERR
Calling (via exec) Stage 3 from Stage 2...
Stage 3 STDOUT
Stage 3 STDERR
Returned from Stage 2 to Stage 1
Under Perl v5.8.0 I get the following:
Stage 1 STDOUT
Stage 1 STDERR
Calling (system) Stage 2 from Stage 1...
Returned from Stage 2 to Stage 1
Now I want it to work like v5.002. You can see I've tried autoflush.
According to Perlfaq8, "With system(), both STDOUT and STDERR will go the
same place as the script's versions of these, unless the command
redirects them."
Any ideas?
Cheers,
Justin