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
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |