<?xml version="1.0" encoding="windows-1252"?>
<node id="1006804" title="Re: System commands using CGI" created="2012-12-03 01:38:19" updated="2012-12-03 01:38:19">
<type id="11">
note</type>
<author id="840762">
rjt</author>
<data>
<field name="doctext">
&lt;p&gt;It's likely that the &lt;c&gt;who&lt;/c&gt; program is not in the &lt;c&gt;$PATH&lt;/c&gt; of the web server's environment. Try printing out &lt;c&gt;$ENV{PATH}&lt;/c&gt; in your CGI program to verify this. Anyway, the more secure route is to specify the full path of the command you want to execute, usually &lt;c&gt;/usr/bin/who&lt;/c&gt; or &lt;c&gt;/bin/who&lt;/c&gt; (check by running &lt;c&gt;which who&lt;/c&gt; from a shell prompt).&lt;/p&gt;

&lt;p&gt;Second, I'm not sure what you intend to do with the text file, but if you intend to show the output inside your CGI program (or even if you don't), you have introduced a race condition by sending the output to the same text file every time. (If two visitors hit the CGI very close together, the first visitor might see the second visitor's &lt;c&gt;who&lt;/c&gt; output.) A better way to handle this is to capture the output with [doc://perlop#qx/STRING/|qx// or backticks].&lt;/p&gt;

&lt;c&gt;my $output = `/usr/bin/who`;
print '&lt;p&gt;Something went horribly awry!&lt;/p&gt;' if $?;&lt;/c&gt;</field>
<field name="root_node">
1006794</field>
<field name="parent_node">
1006794</field>
</data>
</node>
