Thank all of you for advice. Win32::Process::Open seem to be very promissing, only that I do some mistake. I have writen
2 short scripts:
# SCRIPT TO START NOTEPAD.EXE
#!/usr/bin/perl -w
use Win32;
use Win32::Process;
$ApplicationName = 'c:\\windows\\notepad.exe';
$CommandLine = 'notepad';
$CreateOptions = NORMAL_PRIORITY_CLASS | DETACHED_PROCESS;
Win32::Process::Create($ProcessObj,$ApplicationName,$CommandLine,
0, # Don't inherit.
$CreateOptions,
".") # current dir.
or die print_error();
#$ProcessObj->Wait(INFINITE) or warn print_error();
$ProcessObj->Wait(500) or warn print_error();
$ProcessObj->GetExitCode($ExitCode) or warn print_error();
print "[$CommandLine] exited with $ExitCode\n";
sub print_error {
print Win32::FormatMessage( Win32::GetLastError() );
}
$pid = $ProcessObj->GetProcessID();
print "PID: $pid\n\n";
> PID: 3052
>
*******************************************************************************
The PID I get from the running process I pass to the second script:
# SCRIPT TO CHECK RUNNING PROCESS
#!/usr/bin/perl -w
use Win32;
use Win32::Process;
$pid = shift;
Win32::Process::Open($ProcessObj,$pid,1);
$ProcessObj->Wait(INFINITE) or warn print_error();
print "END \n";
$ProcessObj->GetExitCode($ExitCode) or warn print_error();
print "...exited with $ExitCode\n";
sub print_error {
print Win32::FormatMessage( Win32::GetLastError() );
}
----------------------------------------------------------------------------------
Unfortunately I get this message:
>PID: 3052
>
>Access is denied.
>
>END
>...exited with 259
*******************************************************************************
Have you any idea why I keep getting the massage: Access is denied?
I was thinking about windows services as afoken has suggested as well. I need to start about 20000 processes in about 12 hours with about 100 types of command lines - perl scripts, BAT scripts, executables. Some of them run few seconds, some of them run few hours. Is stil this type of tasks suitable to run via Win32::Daemon?
Thanks
Tomas |