http://www.perlmonks.org?node_id=977799

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

UPDATE: Problem solved by adding InheritConsoleHandles mentioned in this fix. Thank you all guys for hints and help!

What can be the reason, that script.pl > output.txt creates empty file output.txt and perl script.pl > output.txt creates output.txt with data produced by script.pl?

I have

This is perl 5, version 14, subversion 2 (v5.14.2) built for MSWin32-x +64-multi-thread (with 1 registered patch, see perl -V for more detail) Copyright 1987-2011, Larry Wall Binary build 1402 [295342] provided by ActiveState http://www.ActiveSt +ate.com Built Oct 7 2011 15:19:36
on Windows 7.

Replies are listed 'Best First'.
Re: redirection problem
by Corion (Patriarch) on Jun 22, 2012 at 09:56 UTC

      Yes, it is unfortunate that the claim of finding the cause stands and that the follow-on discussion doesn't make it clear that that conclusion was in error. I would've made that point more forcefully but I was treading carefully, hoping to avoid an explosive denial and hoping to gently solicit a re-examination and thus a realization and admission.

      If you read the whole thread carefully, you can see that the conclusion is disproved and also what the real source for the conclusion (likely) was. So I consider this specific problem no better understood.

      Here's hoping that this round of investigation can come to a more useful conclusion.

      - tye        

Re: redirection problem
by BrowserUk (Patriarch) on Jun 22, 2012 at 09:08 UTC

    What output do you get from the following two commands?

    C:\test>assoc .pl .pl=Perl C:\test>ftype Perl Perl="c:\perl64\bin\perl.exe" "%1" %*

    Note: The argument to the second command comes from whatever is after the '=' in the output from the first.


    With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    "Science is about questioning the status quo. Questioning authority".
    In the absence of evidence, opinion is indistinguishable from prejudice.

    The start of some sanity?

      Yes, I though it will be something with registry settings, but the output is exactly the same as yours.

        the output is exactly the same as yours.

        Really? You are using a 64-bit perl? Are you sure the quoting of the arguments is exactly the same?

        How about:

        C:\test>set pathext PATHEXT=.pl;.COM;.EXE;.BAT;.CMD;

        With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
        Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
        "Science is about questioning the status quo. Questioning authority".
        In the absence of evidence, opinion is indistinguishable from prejudice.

        The start of some sanity?

Re: redirection problem
by Happy-the-monk (Canon) on Jun 22, 2012 at 09:04 UTC

    What can be the reason, that script.pl > output.txt creates empty file output.txt and perl script.pl > output.txt creates output.txt with data produced by script.pl?

    Does the execution of the first command produce any errors on STDERR (the cmd/dosbox/shell/terminal)?

    What does the first line of script.pl look like?

    What kind of a shell/terminal are you using?

    Cheers, Sören

      No, there are no errors on STDERR:
      C:\>type script.pl #!perl print 'abc' C:\>script.pl > noperl.txt C:\>perl script.pl > perl.txt C:\>type noperl.txt C:\>type perl.txt abc C:\>assoc .pl .pl=Perl C:\>ftype Perl Perl="C:\Perl64\bin\perl.exe" "%1" %*
      I use standard Windows console.

        Do a  dir scrip*

        Also try

        #!/usr/bin/perl -- use strict; use warnings; use File::Find::Rule; use Env qw/ @PATH /; use Data::Dump; dd( find( 'file', 'name', qr/script/i, 'maxdepth', 1, 'in', \@PATH)); __END__
Re: redirection problem
by pvaldes (Chaplain) on Jun 22, 2012 at 11:23 UTC

    because script.pl is not a command recognizable to bash and returns false/null probably, so nothing is printed in the output file

    I use standard Windows console

    I missed this line, forget all said then

      Yeah, if you follow Corions links, you can examples of the error message win32 generates, like this
      $ nonsense > NUL 'nonsense' is not recognized as an internal or external command, operable program or batch file.