I'm hoping I have missed a simple fix to this problem using Win32::Process, but I've done a lot of research and haven't found what I need.
I'm working on a "report engine". The main program queries the DB to retrieve a list of reports to be executed. With that information it builds the needed command line strings, which are then executed as threads using Win32::Process. The problem I'm having is not being able to capture the return from the command line for each thread and redirect it to a logfile. We really need to be able to capture any error messages to help us resolve issues faster and easier.
Here's a simple program file named ThreadLogTest.pl illustrating what I'm trying to accomplish with the redirection.
#!/usr/bin/perl use strict; use Win32; use Win32::Process; my $ProcessObj; my $perl_command = ''; print "Starting thread logging test\n"; $perl_command = 'C:\AS_v5.8.6_Perl\bin\perl.exe D:\FinancialReports_Pe +rlSource\PDS\output_test.pl >MyLog.txt 2>&1'; print "\n$perl_command\n"; Win32::Process::Create($ProcessObj,"C:\\AS_v5.8.6_Perl\\bin\\perl.exe" +,$perl_command,1,CREATE_NO_WINDOW,"."); print "Thread logging test completed\n"; exit;
The output_test.pl code called by ThreadLogTest.pl is
#!/usr/bin/perl print "\n\nThis is a test!\n\n"; exit;
The batch file that starts the whole process is
::Test thread logging @echo STARTED %time% Perl D:\FinancialReports_PerlSource\PDS\PDS_SURE\ThreadLogTest.pl >Thr +eadLogTest.txt 2>&1 @echo COMPLETED %time% @Pause
What I need is to have the output of output_test.pl written to the MyLog.txt file. That doesn't happen. I do get the following output in ThreadLogTest.txt
Starting thread logging test C:\AS_v5.8.6_Perl\bin\perl.exe D:\FinancialReports_PerlSource\PDS\outp +ut_test.pl >MyLog.txt 2>&1 Thread logging test completed
Nothing is written to MyLog.txt. If I copy the command line from ThreadLogTest.txt and execute it as a command then "This is a test" does get written to MyLog.txt, so I know the command line is properly formatted to redirect the output.
I really hope someone has used Win32::Process in a similar fashion, as it seems to be the perfect solution to what we want to accomplish if we can overcome this logging issue with the threads.
Thanks to everyone for your time!
In reply to Redirecting Output From Command Line in Threads by CKCJim
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |