Hello Monks,

Like many others here, I'm trying to use Win32::Proc.

Here are my needs :

There are various ways to launch a process and "monitor" it.

Here is what I have so far :

#!/usr/bin/perl use warnings; use strict; use Win32::Process; use Win32::Process 'STILL_ACTIVE'; my $child_pid; my $child_proc; my $cmd = 'sleep.exe 20'; my $debug = 1; my $exitcode = 1; my $stdout = 'out.txt'; my $stderr = 'err.txt'; Win32::Process::Create($child_proc, $ENV{COMSPEC}, "/c $cmd > $stdout +2>$stderr", 0, 0, ".") || print Win32::FormatMessage( Win32::GetLastE +rror()); $child_pid = $child_proc->GetProcessID(); my ($min_time,$max_time,$kill_time) = (12,15,18); if($child_pid!=0) { print "Started child process id $child_pid\n"; my $i=0; while ( 'true' ) { $child_proc->Wait(1000); $i++; $child_proc->GetExitCode($exitcode); if ( $exitcode == STILL_ACTIVE ) { print "loop $i\n"; if($i==$max_time) { print "max time : this is quite long...\n"; } if($i==$kill_time) { print "kill time : kill $child_pid\n"; $child_proc->Kill(-1); } } else { print "### E = $^E ?=$? ###\n"; print " Process terminated on it's own rc=$exitcode \n"; if($i==$min_time) { print "min time : command was too short\n"; } exit $exitcode; } } } else { print "Can't start process...\n"; }

What is working :

What is not working :

I have seen many threads about redirecting STDOUT and STDERR for the Win32::Process module, but never complete answer about the drawbacks (ability to kill and get real PID)

I'm using 32bits strawberry perl on a 64bits win2k8R2 box. My code needs to work on windows 2003/2008/2012. I can install some CPAN package by hand (the server is not connected to internet, whereas my workstation is)

I have tried several modules like Proc::Background Proc::Simple Proc::Reliable, with no luck.

Any help much appreciated. If some module can help, please tell me

Thank you very much for reading, please forgive my poor english.

Happy new year to you, perl Monks !


In reply to various questions about Win32::Process by nabbo

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.