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

Issue resolved by user bulk88. Thanks!

I'm trying to run my .pl scripts in an automated environment where the scripts are started remotely. My current target is Windows7, but we need to support multiple OSs. I want to be able for the users to redirect console output to a file.

If I open a command console, I have no problems with the following syntax:

Perl script.pl arg1 arg2 > console.out

script.pl arg1 arg2 > console.out

But when I try to put the exact same lines in the run box, the redirect to file is ignored. I reviewed a couple of solutions, one of which suggested adding a -w flag after perl. I tried that and the redirect was still ignored. Any ideas on where I'm going wrong?

I currently have ActivePerl 5.16 installed on Windows7.
assoc.pl returns
.pl=Perl
ftype Perl returns
Perl="c:\perl\bin\perl.exe" "%1" %*

  • Comment on Perl in Windows - STDOUT to file Behavior difference by run context

Replies are listed 'Best First'.
Re: Perl in Windows - STDOUT to file Behavior difference by run context
by bulk88 (Priest) on Mar 12, 2014 at 00:24 UTC
    I debugged a similar problem but not same yesterday/today by chance. See https://rt.cpan.org/Ticket/Display.html?id=50374. When you use the run box, there is no shell/cmd prompt. MSDOS Batch language is not available from the run box. Expect to find a '>' in your @ARGV if you use the run box. You need to type "cmd /c perl foo.pl > text.txt" into run box so the shell processes it and launches perl, not the run box.
      This is exactly what I was looking for. Issue resolved. Thanks bunches!!!
Re: Perl in Windows - STDOUT to file Behavior difference by run context
by dasgar (Priest) on Mar 11, 2014 at 22:55 UTC

    Can you clarify what you mean by "in the run box"? My only guess is that you're clicking on the Start and then clicking on Run. If that's correct, it's possible that your calls to your Perl script and piping to output to a file may be working. However, your examples are using relative path (i.e. using the current directory) instead of a full path. You might want to check the directory where your perl.exe file is located. You just might find the files that you created from your calls from the "run box".

    This may not be a quick and easy thing to do, but you might want to consider redesigning your script(s) to take an optional input argument that specifies a file to log output to rather than relying on using '>' from the command prompt environment to pipe the output to a file.

      Thanks for your reply. After a couple of test runs, I did search the system for the file, but it wasn't anywhere to be found because the redirect wasn't working. Simply logging my output wasn't enough. I inherited a 5000+ line script that calls into a .pm which then calls into a .dll and I needed all output to be in a file for debug and evaluation. One of your peers had the proper cmd line I needed to get it done without extra code.
Re: Perl in Windows - STDOUT to file Behavior difference by run context
by Anonymous Monk on Mar 11, 2014 at 23:31 UTC
Re: Perl in Windows - STDOUT to file Behavior difference by run context
by BrowserUk (Patriarch) on Mar 11, 2014 at 22:54 UTC
    But when I try to put the exact same lines in the run box

    What the heck is "the run box"?


    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.