http://www.perlmonks.org?node_id=1006804


in reply to System commands using CGI

It's likely that the who program is not in the $PATH of the web server's environment. Try printing out $ENV{PATH} 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 /usr/bin/who or /bin/who (check by running which who from a shell prompt).

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 who output.) A better way to handle this is to capture the output with qx// or backticks.

my $output = `/usr/bin/who`; print '<p>Something went horribly awry!</p>' if $?;