> I call command line tools constantly as the third-party application's
API is
> not exposed to Perl any other way.  
>

Sometimes it is unavoidable, sounds like you have done your homework and
tried, kudos.
 
> I am wondering why there are at least three options for executing a
command
> line (including backticks, system() and pipe), if there is a "best" way to
> invoke a command line, or what factors are taken into account to determine
> which to use.  Generally I want the program to wait for the command to
> complete (so I think exec() is not an option), and I want the return code,
> STDOUT and STDERR from the command (so I don't think system() works
for me as
> it doesn't give the command's output.
>   
> I would assume that the pipe is most flexible, but I was unable or too
lazy to
> get it working reliably.  If this is the right approach I will give it
more time.
> 

Your understanding is right on, there are lots of ways so that you
aren't constrained in what you can do. Each can be applied in different
situations depending on what *your* needs are. This is one of the
reasons why Perl is so great, you are not limited by what the language
can accomplish (at least *very* rarely).  Your analysis of system and
backticks is correct, and it sounds like you want the output, sometimes
you won't, in that case go with C<system>. C<system> also allows you to
skip shell interpolation of the command line and exec a program
directly.  A pipe is generally used to talk to the program you are
starting, sometimes in uni- but more often in bi- directional
communication, in other words, maybe the program is expecting you to
give it some info. system/backticks don't provide this (usually).

> So I generally use backticks, but what I (sometimes) don't like about
this is
> that it merges STDOUT and STDERR unless I redirect each to a temp
file.  Since
> sometimes I actually do want the ordered mix, I guess I want one
routine that
> returns an associative array of everything - OS return code, STDOUT,
STDERR,
> and merged STDOUT and STDERR, without using temp files.
> 

backticks and system are both very simple, which is why they are nice.
In the case that you want the streams separated you might want to
consider something like IPC::Open3,

For much more information check out,

perldoc IPC::Open3
perldoc IPC::Open2
perldoc perlipc
perldoc -f system

> TIA,
> 
>    -John
> 

http://danconia.org

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to