Zadeh has asked for the wisdom of the Perl Monks concerning the following question:
I'm trying to write a perl script in windows that will use windows devenv.com command to automate the building of .sln and .vcproj files. Problem is, some of them have custom build steps at the end which launches a test--which sometimes will hang.
So, I'm trying to figure out a way to detect that. My first thought was to try forking a child and communicating with a pipe, but open(FH, "-|") doesn't appear to work in windows, and I'm not sure how to detect a hung state. Thoughts?
Re: Detecting hung conditions in win32
by GrandFather (Saint) on Feb 21, 2006 at 18:39 UTC
|
Take a look at Win32::Process, especially GetExitCode($exitcode) and Wait($timeout).
DWIM is Perl's answer to Gödel
| [reply] [Watch: Dir/Any] |
Re: Detecting hung conditions in win32
by BrowserUk (Patriarch) on Feb 21, 2006 at 21:06 UTC
|
I'd suggest looking at Win32::Process::Info. Start the process and use W::P::I to monitor it's process utilisation . If it fails to change over a period of a few seconds, it is either waiting for input or is hung. Your program logic should allow you to distinguish the difference.
See Re: Win32: Multiple processes with the same name and Re^3: Win32: Multiple processes with the same name for some sample code.
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
Lingua non convalesco, consenesco et abolesco. -- Rule 1 has a caveat! -- Who broke the cabal?
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.
| [reply] [Watch: Dir/Any] [d/l] |
Re: Detecting hung conditions in win32
by jdhedden (Deacon) on Feb 21, 2006 at 18:36 UTC
|
eval {
local $SIG{'ALRM'} = { die("Timeout\n"); };
alarm(60);
system('build.sh');
alarm(0);
};
if ($@ =~ /^Timeout/) {
die("Build timed out\n");
}
Remember: There's always one more bug.
| [reply] [Watch: Dir/Any] [d/l] |
|
Thanks, but a problem there is that it doesn't really detect the hung state, but kills it after a set amount of time (60 seconds), right?
| [reply] [Watch: Dir/Any] |
Re: Detecting hung conditions in win32
by eyepopslikeamosquito (Archbishop) on Feb 21, 2006 at 20:54 UTC
|
As described in Re: Timing Windows commands, I like to use the Win32::Job module (comes standard with ActivePerl, requires Windows 2000 or later) for this sort of thing.
| [reply] [Watch: Dir/Any] |
Re: Detecting hung conditions in win32
by Anonymous Monk on Feb 22, 2006 at 02:14 UTC
|
If it's Win32, it's probably hung.
| [reply] [Watch: Dir/Any] |
|