Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

I was advisd here Module for accessing samba smbclient command to use qx to get the results of a command into a variable. Works in a stand alone script from the prompt, it doesn't output anything when used in a CGI script. I mean the $output doesn't get populated with anything, no error is shown to say the command didn't run. Using a combination of warn and DataDumper I see that $output is empty. Please help.

Node link provided by GrandFather

  • Comment on qx to call command doesn't work via CGI

Replies are listed 'Best First'.
Re: qx to call command doesn't work via CGI
by toolic (Bishop) on Dec 14, 2011 at 16:30 UTC
Re: qx to call command doesn't work via CGI
by choroba (Cardinal) on Dec 14, 2011 at 16:29 UTC
    qx should return undef on error, not an empty string. Check whether the variable is defined. I guess it might be a problem with permissions: note that the CGI script is probably run as a different user than the one who runs it from the prompt.
      I have
      my $command = '/usr/sfw/bin/smbclient -L rest of command goes here +'; my $output = qx{$command}; if (defined $output){ warn "$output defined"; }else{ warn "$output undefined"; } warn Dumper $output;
      Apage error_log shows " defined at samba.pl line...". Apache runs as the same users I'm running the command line example as. I checked this in the httpd.conf and with the whoami command.