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

I have been banging my head for a few hours today on a problem. I am using the latest release of AS Perl and running window xp pro.

It looks like trying to pipe backtick STDERR output to STDOUT doesnt work. Just to make it more simplistic I tried redirecting STDERR to a file like:

my $compileResults = `C:/Perl/bin/perl.exe -c D:/tempPerlScript2860.ipl 2>D:/output.txt`;

...which does not work (meaning I don't see anything within output.txt). However, if I actually just type the following into a windows command prompt, the output.txt file is updated with compilation error message:

C:/Perl/bin/perl.exe -c D:/tempPerlScript2860.ipl 2>D:/output.txt

Any idea on why it would work if I directly input the command into a command line but would not work when I try and execute it via the backticks opperator in a CGI file? From what I can see after reading a lot of information on the subject, it should work fine. Note that I am trying to send it to a file since 2>$1 is not working either.

Replies are listed 'Best First'.
Re: STDERR Redirection problems
by ikegami (Patriarch) on Feb 14, 2010 at 23:49 UTC
    It should work, and it does work for me.
    >type a.pl ` perl -e"print qq{stdout\\n}; warn qq{stderr\\n};" >stdout 2>stderr ` >perl a.pl >type stdout stdout >type stderr stderr

    Just to make it more simplistic I tried redirecting STDERR to a file [...] ...which does not work (meaning I don't see anything within output.txt).

    So where does it go? If nowhere, then you are either getting a message such as "Access is denied" on STDERR or the child doesn't send anything to STDERR.

Re: STDERR Redirection problems
by Marshall (Canon) on Feb 15, 2010 at 05:59 UTC
Re: STDERR Redirection problems
by Anonymous Monk on Feb 14, 2010 at 23:30 UTC
    permissions and %ENV
      To clarify for the OP: the environment and user you are running in on a web server is probably different to that in use on the command line.

        Thank you for this reply as it is the only thing that seems to be the potential problem given that running the command directly on the command line works, while running it via a CGI running through IIS does not work.

        Any idea on how to follow up on this?

Re: STDERR Redirection problems
by Anonymous Monk on Feb 14, 2010 at 23:37 UTC
    2>$1 is bash/csh syntax, on win32 your shell is usually cmd, not bash
    $ perl -V:sh sh='cmd /x /c';

      cmd uses the same syntax to provide the same feature:

      >perl -e"warn 'stderr'" 2>stderr >type stderr stderr at -e line 1.
        stderr isn't $1 you nitpicker
          A reply falls below the community's threshold of quality. You may see it by logging in.
      The Microsoft website is (sometimes) your friend: see here