<?xml version="1.0" encoding="windows-1252"?>
<node id="843512" title="Re: system and backticks" created="2010-06-07 11:20:17" updated="2010-06-07 11:20:17">
<type id="11">
note</type>
<author id="840762">
rjt</author>
<data>
<field name="doctext">
&lt;p&gt;For those that learn by example:&lt;/p&gt;

&lt;code&gt;
my $cmd = 'echo "Hello World" &amp;&amp; exit 2';
my $sys_result = system($cmd);
print "system() returned `$sys_result'; \$? = $?\n";

my $qx_result = `$cmd`;
print "qx// returned `$qx_result'; \$? = $?\n";
&lt;/code&gt;

&lt;p&gt;Output:&lt;/p&gt;
&lt;code&gt;
Hello World
System returned `512'; $? = 512
qx// returned `Hello World
'; $? = 512
&lt;/code&gt;

&lt;p&gt;In a nutshell, with [doc://system], the command's output will not be captured (note how "Hello World\n" goes to the terminal), and you get the exit status as the return value. With [doc://perlop#`STRING`|backticks], the command's stdout is captured, and you get that output as your return value. In both cases, the child error is available with [doc://perlvar#$CHILD_ERROR|$?].&lt;/p&gt;

&lt;p&gt;If you need to capture standard error, you will need to redirect it to standard output by appending 2&gt;&amp;1 to your command, or perhaps use the completely different [mod://IPC::Open3].&lt;/p&gt;

&lt;p&gt;Please review [id://174051] and feel free to ask a more specific question if none of these replies are telling you what you need to know.&lt;/p&gt;</field>
<field name="root_node">
843492</field>
<field name="parent_node">
843492</field>
</data>
</node>
