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

Well, now I've done it. I've got a perl script that calls another script (it doesn't matter what language, but perl works). If I open up a command window (I'm using XP) and say:
The script executes wonderfully, and I get ALL the output of the original script ("" in this case) and the programs that the script runs. If I attempt to re-direct the output of the script like:
C:> >log_file.txt
The only thing written to the output file is the output generated by the original script (""). The output of the decendants (system...) of "" just disappear! Now for the 'wierdness'. If I say:
C:> perl >log_file.txt
at the command line, the log file will receive all the text written by the script, and its decendants, which is the same output generated by the first example. The big question: HUH? Why does it behave differently if invoked in the various ways? In my Unix background this wouldn't be different (I'll let others verify my error if not!). I show the code for "" for reference:
#!/usr/bin/perl -w if (!defined $ARGV[0]) {$ARGV[0] = 3}; print "Argv[0] is $ARGV[0] \n"; print "Just a line to see what happens\n"; # Just to make it fun $less = $ARGV[0] - 1; if ($less) { print "Call with one less: $less \n"; system (" $less"); print "System returned $? (not that I care!)\n"; }
Yes, this is a bit silly, but it demonstrates my point. I am running on windows (XP), so forgive me. Thanks.

Replies are listed 'Best First'.
Re: Inheritance of files on windows
by bmann (Priest) on Jan 31, 2006 at 23:25 UTC
    No, it's not silly - see the seemingly unrelated Re: Strange "There is not enough space on the disk" error (Win32) as well as perlwin32faq5:
    STDIN and STDOUT, and Piping don't always work on NT/2000.

    You may get unexpected results when you try to redirect the output of files that use Windows NT/2000's file association feature. You can use PerlApp or pl2bat to convert a Perl script to an executable or a batch file. This should solve any problems you may have with redirection.

    Another alternative that works is to run the script as perl (which you did).

    You can add XP to the list of OSes on the first line. I've searched, but I've never seen a complete explanation for this oddity.