Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Re: Show Unix Talk?

by hacker (Priest)
on Oct 25, 2002 at 11:58 UTC ( [id://207967]=note: print w/replies, xml ) Need Help??


in reply to Show Unix Talk?

Or, you could do it in a more proper fashion by using IPC::Open3 and capture the success or failure of that command you're executing in the shell. `backticks` are something you should never EVER use, ever. If you insist on using them, ALWAYS make sure to use the /full/path/to/binary in the `call` you use.

You could also use "system()-in-list-mode" to try to get what you want, and make sure to wrap your calls in something that can return success or failure.

Alternately, you can do something like:

# sets $list to 0 if the ls worked $list = system("ls") or die "Failed; $!";

You may have to set up your own signal handler to capture SIGPIPE and others. If you use `backticks` to execute this command, $? will not be set to what you expect (check perlvar for more details on what $? means).

perlfaq8 also has a section on this exact topic. Give it a read, it may prove enlightening.

While I agree with sauoq about NOT turning your web browser into a remote shell, his suggestion of using `backticks` for this is slightly incorrect, given your request (though I see his sarcasm in suggesting it). Backticks will execute a system command and return what was sent to STDOUT by that command. You only want to test the success or failure of that system command, two very different things. Good luck!

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others rifling through the Monastery: (4)
As of 2024-09-20 16:28 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    The PerlMonks site front end has:





    Results (26 votes). Check out past polls.

    Notices?
    erzuuli‥ 🛈The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.