use Win32::Job; sub runmons { my ($job, $pid, $ro, $timeout, $rs, $state, $w, $pfx); init(); oprn("Starting script " . basename($0) . '...', c::STARTPFX, $0); $job = Win32::Job->new(); die 'Failed to create Job object' unless ($job); oprn("Spawning process to run $CHILD...", c::NOTEPFX, $0); $pid = $job->spawn(undef, "perl $CHILD $0"); die "Failed to spawn process to execute $CHILD" unless ($pid); $ro = XMLin(c::MONOPTS, ForceArray => 1); $timeout = $ro->{timeoutsecs}[0]; die 'Timeout length not specified in ' . c::MONOPTS unless defined($timeout); oprn("Running $CHILD as PID $pid with a timeout of $timeout seconds...", c::NOTEPFX, $0); $job->run($timeout); $rs = $job->status(); $state = $rs->{$pid}{exitcode}; unless (grep { $state == $_ } @c::KNOWNERRVALS) { oprn("Error: received unknown exit code = $state from $CHILD. Will convert to exception.", c::ERRPFX, $0); $state = c::EXCEPT; } $state == c::SUCCESS ? ($pfx = c::NOTEPFX) : ($pfx = c::ERRPFX); $w = errword($state, $0); oprn(basename($0) . " received exit code $state from $CHILD ($w).", $pfx, $0); return $state; };