You might be able to use Win32::Process.

Here is an example of finding a process (Notepad) by executable name then monitoring it and taking action when it terminates:

use strict; use warnings; use Data::Dumper::Concise; use Win32::Process::List; use Win32::Process; my $p = Win32::Process::List->new(); my %list = $p->GetProcesses(); foreach my $pid (keys %list) { if($list{$pid} eq 'notepad.exe') { my ($obj, $iflags); Win32::Process::Open($obj, $pid, $iflags) or die "Win32::Process::Open failed"; $obj->Wait(INFINITE); print "Done waiting\n"; exit(0); } } print "Notepad process not found\n";

And here is an example of starting Notepad from Perl, and restarting it when it exits:

use strict; use warnings; use Data::Dumper::Concise; use Win32::Process; my $obj; while(1) { Win32::Process::Create($obj, "C:\\windows\\system32\\notepad.exe", "notepad", 0, NORMAL_PRIORITY_CLASS, ".") or die "Failed to start notepad"; $obj->Wait(INFINITE); print "Notepad exited - restarting\n"; }

If you want to do something while the process continues to run, you can do that too:

use strict; use warnings; use Data::Dumper::Concise; use Win32::Process; my $obj; while(1) { Win32::Process::Create($obj, "C:\\windows\\system32\\notepad.exe", "notepad", 0, NORMAL_PRIORITY_CLASS, ".") or die "Failed to start notepad"; while(1) { $obj->Wait(10000); my $exit_code; $obj->GetExitCode($exit_code); if($exit_code == Win32::Process::STILL_ACTIVE()) { print localtime() . ": Do something while notepad runs\n"; } else { print localtime() . ": Do something when notepad terminate +s\n"; last; } } }

In reply to Re: monitor iperf from perl by ig
in thread monitor iperf from perl by mark4444az

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.