I have a Perl script that launches another Perl script in a new console through Win32::Process as follows:
Win32::Process::Create($ProcessObj,
"C:\\Perl\\bin\\perl.exe",
"$path_to_other_perl_script",
0,
NEW_CONSOLE,
".");
$ProcessObj->Suspend();
$ProcessObj->Resume();
$ProcessObj->Wait(0);
The problem is, there is no stdout in the new console created. If I don’t use the new console option, the script runs silently in the background.
If I use cmd.exe to launch the Perl script, I can see the output fine but now I cannot control the child Perl script through Win32::Process.
Does anyone have a solution that works?
Update: Based on your comments, I get the feeling that your programs are not examples of best practices on Linux or Windows. However, I am sure, when reading the documentation for
Win32::Process, you noticed that you can call theKillmethod on the process to terminate it. So, I changed the example below to do that.Your chances of getting useful help increase exponentially if you provide real code. Here are the arguments to
Win32::Process::Create:$iflags: flag: inherit calling processes handles or notNow, I am not sure if you are trying to capture the
STDOUTof the second process or if you are trying to have itsSTDOUToutput show up in the same console as the parent.If the latter, then the following scripts illustrate one way of doing that:
parent.pl
hello.pl
Output:
Now, I am still not sure why you are using
Win32::Process. Unless there is a specific reason to tie your script toWin32, I would recommend using standard Perl facilities. For example, readperldoc -f openandperldoc perlipc(see esp. Using open for IPC).Explain your question better to get answers that address your particular situation rather than generalities.