Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Re: How to read from shell command and terminate it afterwards?

by BrowserUk (Patriarch)
on Feb 10, 2012 at 09:30 UTC ( [id://952963]=note: print w/replies, xml ) Need Help??


in reply to How to read from shell command and terminate it afterwards?

Why other people are making such a meal of this I do not know. Here's the easy way:

my $pid = open PIPE, "theCommand arg1 arg2 |" or die $!; my @input = map scalar <PIPE>, 1 .. 4; ## kill 3, $pid;

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.

The start of some sanity?

Replies are listed 'Best First'.
Re^2: How to read from shell command and terminate it afterwards?
by ikegami (Patriarch) on Feb 10, 2012 at 09:36 UTC

    Why other people are making such a meal of this

    Because the OP didn't mention anything about 4 lines?

      True. He said:

      This command outputs to stdout [a] few lines of information, which I am looking for ...

      "a few" is generally more than two, and less than say 10. "a few" emphasizes the fact that the number, while small, is not zero but more than two.

      But mostly it suggests he knows how many.


      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.

      The start of some sanity?

        No, it does not suggest he knows (exactly) how many. In fact, the OP was pretty clear that the length of the output depends on external factors.

        He *may* know exactly how many lines he needs to read, so I'm not saying that your solution isn't viable. I'm just answering your question.

        What if this small number varies :) ? It can be three, two, five, depending on the circumstances? Then relying on that number can lead to data loss or blocking read.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others wandering the Monastery: (4)
As of 2024-04-18 18:35 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found