in reply to Re^6: Test whether STDOUT is connected to a file
in thread Test whether STDOUT is connected to a file

However even this explanation doesn't satisfy completely: If indeed no redirection is performed by Perl, the called process should see the arguments ">...", "2>&1" in @ARGV, but they are not present. Something is eating them without doing proper redirection...

No. Consider

#!/usr/bin/perl -- unlink 'out.txt'; system 1, $^X, '-MData::Dumper', '-le','print(1);warn(2);print Dumper( +\@ARGV);', '>out.txt 2>&1'; sleep 1; print `cat out.txt`, "\n",'-'x66,"\n"; sleep 1; print `pslist |grep -c cmd`,"\n",'-'x66,"\n"; system 1, 'perl.exe -MData::Dumper -le "print(1);warn(2);print `pslist + |grep -c cmd`, Dumper(\@ARGV)" >out.txt 2>&1'; sleep 1; print `cat out.txt`, "\n",'-'x66,"\n"; __END__ 1 2 at -e line 1. $VAR1 = [ '>out.txt 2>&1' ]; cat: out.txt: No such file or directory ------------------------------------------------------------------ pslist v1.28 - Sysinternals PsList Copyright ¬ 2000-2004 Mark Russinovich Sysinternals 8 ------------------------------------------------------------------ 2 at -e line 1. 1 pslist v1.28 - Sysinternals PsList Copyright ¬ 2000-2004 Mark Russinovich Sysinternals 9 $VAR1 = []; ------------------------------------------------------------------
After the 2nd system there is one more cmd process, and @ARGV no longer contains out.txt, ie it is the shell that does redirection.

You can use Proc::Background to launch processes in the background

Replies are listed 'Best First'.
Re^8: Test whether STDOUT is connected to a file
by rovf (Priest) on Aug 20, 2010 at 07:53 UTC
    Indeed, you are right!! Now I can see this too. Thank you also for pointing out Proc::Background!

    -- 
    Ronald Fischer <ynnor@mm.st>