Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Inheritance of files on windows

by herby1620 (Monk)
on Jan 31, 2006 at 22:55 UTC ( [id://526914]=perlquestion: print w/replies, xml ) Need Help??

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:
C:> script.pl
The script executes wonderfully, and I get ALL the output of the original script ("script.pl" in this case) and the programs that the script runs. If I attempt to re-direct the output of the script like:
C:> script.pl >log_file.txt
The only thing written to the output file is the output generated by the original script ("script.pl"). The output of the decendants (system...) of "script.pl" just disappear! Now for the 'wierdness'. If I say:
C:> perl script.pl >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 "script.pl" 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 ("script.pl $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 script.pl (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.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://526914]
Approved by Paladin
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others taking refuge in the Monastery: (2)
As of 2024-04-24 23:46 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found