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

Hi, I am having this problem with redirection in perl, on a Win NT operating system. Basically I have a perl script lets call it script1 which is calling this other script2, whose output I am trying to redirect. My script2 is calling another script lets call it script3 using the system command.
#script1.prl use diagnostics -verbose; use FileHandle; FileHandle::autoflush STDOUT 1; print "In script 1\n"; unlink ("gg"); system ("script2.prl > gg"); FileHandle::autoflush STDOUT 1; exit;
#script 2 use diagnostics -verbose; use FileHandle; FileHandle::autoflush STDOUT 1; print "In script 2\n"; system ("script3.prl"); FileHandle::autoflush STDOUT 1; exit;
#script3 use diagnostics -verbose; use FileHandle; FileHandle::autoflush STDOUT 1; print "In script 3\n"; FileHandle::autoflush STDOUT 1; exit;

I have tried this both on UNIX and an NT. On UNix it weoks fine with the output being:
in script 1

and gg:
in script 2
in script 3

for some reason on NT it fails. the ouput is the same but gg:
in script 2

it is not storing the ouput of script 3 in gg on NT. please help

Replies are listed 'Best First'.
(tye)Re: Perl redirection in Win-NT
by tye (Sage) on Aug 16, 2001 at 01:33 UTC

    This is a bit of a FAQ. I suggest you read the documentation included with pl2bat. For example, here.

            - tye (but my friends call me "Tye")
Re: Perl redirection in Win-NT
by Rudif (Hermit) on Aug 16, 2001 at 01:37 UTC
    The winnt shell (cmd.exe) is neither here nor there (some would say that it's broken).

    But, if you invoke your script2 like so:
    system ("perl script2.pl > gg") ...

    #script1.pl use diagnostics -verbose; use FileHandle; FileHandle::autoflush STDOUT 1; print "In script 1\n"; unlink ("gg"); #system ("script2.pl > gg"); system ("perl script2.pl > gg"); FileHandle::autoflush STDOUT 1;
    ... it produces the expected output
    H:\devperl\perlmonks>type gg In script 2 In script 3
    HTH
    Rudif
      hi, do you have any idea why this happens though on Win NT ?? why does it work with perl.exe calling the script ?? Thanks
        I don't know. See also the node that tye pointed to, above, for a more informed opinion.
        Rudif
Re: Perl redirection in Win-NT
by RayRay459 (Pilgrim) on Aug 16, 2001 at 01:59 UTC
    Try calling your script with "perl" in front. ...ie..system(perl script1.pl >xx) etc.. Ray