Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Re: Perl System('') question

by Skeeve (Parson)
on Nov 29, 2008 at 08:42 UTC ( [id://726749]=note: print w/replies, xml ) Need Help??


in reply to Perl System('') question

And another alternative is to use open:

my $result; # first open or die open my $eject, '-|', 'eject -n' or die "Can't eject: $!\n"; # Then read in lineby line while (<$eject>) { next unless /^device is/; # until the result is found $result= $_; last; } # done close $eject;

Especially when filtering output, I prefer this method because you can loop over the output line by line and react as soon as you found your searched input.


s$$([},&%#}/&/]+}%&{})*;#$&&s&&$^X.($'^"%]=\&(|?*{%
+.+=%;.#_}\&"^"-+%*).}%:##%}={~=~:.")&e&&s""`$''`"e

Replies are listed 'Best First'.
Re^2: Perl System('') question
by pobocks (Chaplain) on Nov 29, 2008 at 10:26 UTC
    Hmmm... What does this do to a program that's still running when you "last" out of the loop? Like, say you're running a find, and want to kill the find as soon as it spots the thing it's looking for?
    for(split(" ","tsuJ rehtonA lreP rekcaH")){print reverse . " "}print "\b.\n";
      close $eject; will wait for the child to end (after closing pipes to the child?) If you wish to save it from doing extra work, you could ask it to end by sending a TERM signal to it before calling close. The return value of open '-|' is the child's PID.

        ++ to both of you! I didn't think about that yet.


        s$$([},&%#}/&/]+}%&{})*;#$&&s&&$^X.($'^"%]=\&(|?*{%
        +.+=%;.#_}\&"^"-+%*).}%:##%}={~=~:.")&e&&s""`$''`"e
      close $eject; will wait for the child to end (after closing pipes to the child?) If you wish to save it from doing extra work, you could ask it to end by sending a TERM signal to it before calling close. The return value of open '-|' is the child's PID.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others lurking in the Monastery: (3)
As of 2024-04-19 21:19 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found