Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?

Re^4: Stop Command In Perl

by monsoon (Pilgrim)
on Jul 12, 2012 at 18:40 UTC ( #981472=note: print w/replies, xml ) Need Help??

in reply to Re^3: Stop Command In Perl
in thread Stop Command In Perl

I think windows doesn't quite respect 'kill'. This (run on Windows 7 Professional, ActivePerl v5.12.4)
perl -e "$pid = open PIPE, '-|', 'echo one two';$/=' '; while (<PIPE>) +{ print; kill 2, $pid}"

one two

But this
perl -e "$pid = open PIPE, '-|', 'echo one two';$/=' '; while (<PIPE>) +{ print; close PIPE}"


Replies are listed 'Best First'.
Re^5: Stop Command In Perl
by mbethke (Hermit) on Jul 12, 2012 at 22:21 UTC

    Sure, I'd expect the signal emulation in Windows to be incompatible in some way but this particular phenomenon I blame on buffering. It's very very likely that the "echo" will have finished its output before the Perl process gets scheduled again so by the time the while() starts the whole output is sitting in STDIN's buffer already. You could try spawning the Windows equivalent of "(echo one; sleep 1; echo two)" and kill()ing that.

      Tried. Still get
      with this
      perl -e "$pid = open PIPE, '-|', 'echo one && ping -n 5 >nul + && echo two';$/=' '; while (<PIPE>){ print $_ . \"\n\"; kill 2, $pid +}"
      Doesn't look like a buffering issue, more of a kill portability one.
        Well, in this case you'd have to leave $/ alone because there will be no spaces in your output, only newlines. There should be an extra blank line at the end of your output, right? The replies to this suggest kill 2, $pid does indeed work on Windows.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://981472]
[james28909]: what i am trying to accomplish is piping the output of ffmpeg to yet another encryption routine using libsodium. and hopefully once that is done i will be able to forward the packets to discord servers
[RonW]: choroba: Please define "high end" and "low end"
[LanX]: choroba: subversive (as usual ;)
[james28909]: i dunno, if i didnt have so little experience in linux i would swap. but it would be to much of a learning curve for me right now.
[choroba]: Low-end is defined as the Perl that generates millions of income
[choroba]: sorry, that's high-end, of coursse
[choroba]: low end, in my talk, will be code that "we don't touch because it works" and noone knows why
[choroba]: I want to present the most bizzare bugs and misfeatures I met when working for a large financial institution
[choroba]: I already gave a similar talk to my friends in a pub and at an internal conference at work and people liked it, so maybe...
[choroba]: LanX: That's the heritage, I can't do anything else

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (17)
As of 2017-05-22 21:31 GMT
Find Nodes?
    Voting Booth?