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

Re^2: Reading output of external program without Shell

by haukex (Archbishop)
on Nov 15, 2017 at 13:47 UTC ( [id://1203476]=note: print w/replies, xml ) Need Help??


in reply to Re: Reading output of external program without Shell
in thread Reading output of external program without Shell

Good choice to use File::Temp and the list form of system, but don't forget to check its return value - like system(...)==0 or die "system failed, \$?=$?";

Not very elegant thought...

I think this is a case where reliability is elegant :-) Temp files are unlikely to have filename conflicts, are created in locations where they don't disturb the user (unlike some programs that create temp files in the user's home directory and/or use fixed names), and you get automatic cleanup (although I'm not sure why you set UNLINK=>0). Overall they're a good solution, and in fact IPC::Run3 makes heavy use of them, AFAIK it's one of the reasons it's so portable.

Replies are listed 'Best First'.
Re^3: Reading output of external program without Shell
by Anonymous Monk on Nov 15, 2017 at 15:11 UTC
    Strongly agree – "it is elegant if it works, reliably and consistently, and does not take a lot of head-banging to develop." Such "inelegant" procedures also have the advantage of being easier to debug, or to change to meet future requirements, because they do employ a temporary file whose contents can be inspected. (And also because, "first, one step runs and runs to completion, then, the next step begins," and so on.)

Log In?
Username:
Password:

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

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

    No recent polls found