Studio:How do I start non-blocking scripts which do not use the Reporter from a Perl script?
A set of STRIDE objects, including reporter, are automatically instantiated when a script is started in STRIDE Studio. If none of the those objects need to be instantiated you can start a script extern to STRIDE.
use Win32;
use Win32::API;
use Win32::Process;
use constant WIN32_STILL_RUNNING => 259;
my $processObject;
my $retValue = Win32::Process::Create(
$processObject,
$^X,
"perl PATH_TO_MY_SCRIPT ARGUMENTS",
0,
NORMAL_PRIORITY_CLASS,
".") || die Win32::FormatMessage(Win32::GetLastError());
Once you have started the process this way, you can use GetExitCode to check if it is still running, as shown in the following example:
$processObject->GetExitCode($exitCode);
if ($exitCode == Win32_STILL_RUNNING) {
## it is still running
}
else {
## it has finished
}
You can kill the process by using
$processObject->Kill(255);
Using the above statement forces a kill and is not a graceful way to force the process to exit. If your script is a daemon-like process, it is recommended that you use some sort of IPC mechanism (such as Win32::Event or sockets, pipes, semaphores, etc.) to force a more graceful shutdown.