CreateProcess expects a program and its arguments — not some command for some shell — so ">MyLog.txt" and "2>&1" are being passed to Perl which passes them to your script where you completely ignore them.

What you want is for a cmd shell to execute the string as shell command. That's not gonna happen if you don't run a cmd shell. Executing the following should do the trick:

cmd /c "...the shell command..."

You could also do the redirection yourself, thus avoiding having to load a shell.

use IPC::Open3 qw( open3 ); open(local *TO_CHLD, '<', 'nul') or die; open(local *FR_CHLD, '>', 'MyLog.txt') or die; open(local *FR_CHLD_ERR, '>', 'nul') or die; my $pid = open3('<TO_CHLD', '>FR_CHLD', '>FR_CHLD_ERR', 'C:\AS_v5.8.6_Perl\bin\perl.exe', 'D:\FinancialReports_PerlSource\PDS\output_test.pl', ); waitpid($pid, 0); # To wait for child to finish.

Update: Added alternative.


In reply to Re: Redirecting Output From Command Line in Threads by ikegami
in thread Redirecting Output From Command Line in Threads by CKCJim

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.