Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options

Re^7: Perl Background processes in Windows

by gepebril69 (Scribe)
on Jan 31, 2012 at 14:30 UTC ( #950988=note: print w/replies, xml ) Need Help??

in reply to Re^6: Perl Background processes in Windows
in thread Perl Background processes in Windows

Thanks very much for your help and information. With this info I could solve my issues rapidly. I rebuild the example of Peter Dragon for my usage:
sub start_child { my $Cmd = $_[0]; my $CmdOptions = $_[1]; my $ChildProc; my $ChildPid; die "cannot execute cmd: $Cmd" unless (-x "$Cmd"); require Win32::Process; Win32::Process::Create($ChildProc, $Cmd, $CmdOptions, 0, 0, ".") || +confess "Could not spawn child: $!"; $ChildPid = $ChildProc->GetProcessID(); # catch early child exit, e.g. if program path is incorrect sleep(1.0); POSIX::waitpid(-1, POSIX::WNOHANG()); # clean up any defunct child p +rocess if (kill(0,$ChildPid)) { print "Started child process id $ChildPid\n"; } else { warn "Child process exited quickly: $Cmd: process $ChildPid"; } return $ChildPid; } $ChildPid = start_child($Cmd1, $Cmd1Options); sleep(5.0); $ChildPid = start_child($Cmd2, $Cmd2Options);
At the moment I stop the childs by TASKKILL /F /PID of the commands I've started. Not the nicest solution, better to do it with interrupts, but I haven't read that part of the Perl cookbook yet ;)

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://950988]
[Discipulus]: do you know the google like translation: a rich.. as a camel through the needle hole?
[choroba]: yes, I've read about it and its probable original form
[Discipulus]: Tomas in greek ~140Ad
[Discipulus]: also the 'today bred' was probably 'tomorrow's bred'

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (10)
As of 2017-11-23 20:46 GMT
Find Nodes?
    Voting Booth?
    In order to be able to say "I know Perl", you must have:

    Results (338 votes). Check out past polls.