Win32::Process::Create creates processes, not threads. You might think that this is semantics, but the distinction is important - you will just confuse everyone if you talk about threads when you mean processes. If you are not sure of the difference, threads are several concurrent paths of execution within the
same process, and require specialised techniques (not to mention the odd pagan incantation).
Meanwhile, back at your code,
ikegami suggested some solutions, although you have a couple of problems with your code.
Your
$perl_command has single back-slashes in it, which 'escapes' the character which follows (gives it a special meaning, or removes a special meaning if it had one). You did it right in the second parameter to Win32::Process::Create by using \\.
You should always test your return value when you can - if you get the chance to trap an error then take it!
Finally, you might find it easier to use the comspec environment variable to give you the path to the shell.
Here are my suggestions with modifications adapted to run on my system (you will have to alter the paths, watch those \):
#!/usr/bin/perl
use strict;
use Win32;
use Win32::Process;
my $ProcessObj;
my $perl_command = '';
print "Starting thread logging test\n";
$perl_command = "$ENV{comspec} /c C:\\perl\\bin\\perl.exe C:\\output_t
+est.pl >MyLog.txt 2>&1";
print "\n$perl_command\n";
my $result = Win32::Process::Create($ProcessObj,$ENV{comspec},$perl_co
+mmand,1,CREATE_NO_WINDOW,".");
if ($result == 0) {
die "Error: ",Win32::FormatMessage( Win32::GetLastError() ),"\n";
}
print "Thread logging test completed\n";
By the way, you shouldn't really need a shell to do this redirection for you. The C/C++ Win32 API CreateProcess has a struct within it which includes handles for stdin, stdout and stderr of the child process. It is a great shame that the implementor of Win32::Process::Create chose to omit these.
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.