Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Re: Windows run an exe print its output and cut it off after a time

by kcott (Abbot)
on Oct 12, 2012 at 15:43 UTC ( #998728=note: print w/ replies, xml ) Need Help??


in reply to Windows run an exe print its output and cut it off after a time

G'day anshumangoyal,

perlport - alarm indicates that alarm is emulated under Win32. Please show the code you tried.

perlport - open says |- and -| are not supported under Win32. Perhaps this is related to your problem - if it is, perlfork provides a workaround.

How are you terminating $Command? kill, waitpid and their perlport links may be of interest.

-- Ken


Comment on Re: Windows run an exe print its output and cut it off after a time
Select or Download Code
Re^2: Windows run an exe print its output and cut it off after a time
by BrowserUk (Pope) on Oct 12, 2012 at 16:18 UTC

    "Emulated" or not, alarm works fine on Windows. As do both forms of piped open:

    C:\test>perl -E"alarm 5; say(),sleep(1) for 1 .. 10" 1 2 3 4 5 Terminating on signal SIGALRM(14) C:\test>perl -E"$p=open I, '-|', 'ver'; say <I>" Microsoft Windows [Version 6.0.6001] C:\test>perl -E"$p=open O, '|-', 'find \"1\"'; say O for 1 .. 10" 1 10

    With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    "Science is about questioning the status quo. Questioning authority".
    In the absence of evidence, opinion is indistinguishable from prejudice.

    RIP Neil Armstrong

      Well blow me down, BrowserUK is correct. I've never gotten alarm() to work reliably on Windows - perhaps because I'm not that versed in Signals and didn't know what I was doing or was trying on a system call without the eval/die as described in alarm; however, alarm() added in my original script works:

      use strict; use warnings; my $pid = open(my $fileHandler, '-|', "./test.exe" ); my $DONE = 0; $SIG{ALRM} = sub { $DONE = 1 }; alarm 2; while (<$fileHandler>) { print "$_\r"; # \r to not overrun output screen buffer last if ($DONE) } print "\nTimeout! - Time to kill pid: $pid\n"

      And the output

      VinsWorldcom@C:\Users\VinsWorldcom\tmp> TimeThis test.pl TimeThis : Command Line : test.pl TimeThis : Start Time : Fri Oct 12 13:01:09 2012 114601 Timeout! - Time to kill pid: 4700 TimeThis : Command Line : test.pl TimeThis : Start Time : Fri Oct 12 13:01:09 2012 TimeThis : End Time : Fri Oct 12 13:01:12 2012 TimeThis : Elapsed Time : 00:00:02.454

      I thought alarm did work fine but the OP wrote "... alarm is not working in windows.". As I don't have a Windows Perl in front of me, I checked the doco. I wasn't trying to make any point by using the word emulated - that's just what the doco says: "alarm Emulated using timers ...".

      Scrolling down the perlport page a bit after reading about alarm, I came across the open entry by chance. It seems the doco is just wrong with respect to piped open. perlport says it's "unsupported"; perlfork says it's "not yet implemented".

      Thanks for the example code.

      -- Ken

        that's just what the doco says: "alarm Emulated using timers ...".

        In the sense that the OS has neither a native alarm API nor *nix-style signals, it is emulated.

        But then again, under modern versions of *nix including linux, the original form of alarm is also "emulated with timers", so not so different.

        perlport says it's "unsupported"; perlfork says it's "not yet implemented".

        A lot of those more obscure docs have never been updated to reflect the current state of play unfortunately.


        With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
        Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
        "Science is about questioning the status quo. Questioning authority".
        In the absence of evidence, opinion is indistinguishable from prejudice.

        RIP Neil Armstrong

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://998728]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (12)
As of 2014-09-18 12:23 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (113 votes), past polls