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 $?;
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: System commands using CGI
by nikhilB (Initiate) on Dec 03, 2012 at 06:48 UTC | |
by rjt (Curate) on Dec 03, 2012 at 09:05 UTC | |
by Anonymous Monk on Dec 03, 2012 at 07:35 UTC | |
by bitingduck (Chaplain) on Dec 03, 2012 at 16:32 UTC |