Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

A little-known (and perhaps undocumented) feature of Perl is that a trailing "2>&1" on a command will be handled by Perl itself (not the shell) if there is no other reason to use a shell (if there are no other shell metacharacters in the given command string). (At least that was true quite a while ago when I was reading some of the Perl source code and I don't expect such a feature to be removed.)

So this problem would go away if the (useless) single quotes were removed from the example $cmd string. Yes, that "fix" likely won't work for the real problem.

I find it unfortunate that there is no way to trigger this feature when passing a list to system.

Update: Note that there are several modules to choose from that do "IPC" or "run commands" that can handle the "2>&1" for you. Or you can just handle it yourself using open (the 'fork' and 'dup' forms) and exec. Maybe I'll post an example of doing that in a reply, since I'd have to reread a few things to be able to write such.

- tye        


In reply to Re^2: Unable to grab STDERR from a backtick command (2>&1) by tye
in thread Unable to grab STDERR from a backtick command by reasonablekeith

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others cooling their heels in the Monastery: (4)
As of 2024-04-26 09:26 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found