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

This has got me stumped, and I've not run into this issue before.

I have a cgi program whereby I want to run a system command...

system("ffmpeg -blah blah blah");

Now in my browser, the cgi reads nicely, but the system command does not run.

In the command line, if I type: "./myfile.cgi" or "perl myfile.cgi", the system command works.

So... Why does it not run when asked to when using the browser? I've poked around with suexec, and looked at logs, but just can't seem to come up with an answer that works.

I know it must be simple, but I'm having trouble seeing the light.

Thanks in advance!!

Carter

Replies are listed 'Best First'.
Re: Why can't a run a system command?
by philcrow (Priest) on Oct 17, 2006 at 19:32 UTC
    This probably has to do with paths and permissions. The cgi script runs as the web server user (like nobody or apache), while you run as a regular user. The web server user is usually purposely limited to a fixed path (maybe no path at all) and owns only files specifically assigned to it.

    The solution is usually to specify a full path like:

    /usr/local/bin/executable
    and to make sure that the web server user can read and execute that file. Then ask yourself whether that script could do anything to harm your system.

    Phil

      I feel so silly happy right now.. that worked perfectly. Thank you, thank you.
Re: Why can't a run a system command?
by coldmiser (Hermit) on Oct 17, 2006 at 19:30 UTC
    Instead of:
    system("ffmpeg -blah blah blah");
    try:
    $output=`ffmpeg -blah blah blah`; print $output
    It could be something as simple as not being in the right path.
      You really should put the full path to any system commands that are run from a CGI. You cannot guarantee that $ENV{PATH} in the CGI environment will be the same as it is during your login session.
        You really should put the full path to any system commands that are run from a CGI. You cannot guarantee that $ENV{PATH} in the CGI environment will be the same as it is during your login session.

        Furthermore, it's a FAQ too, and a suitable Super Search reveals quite a lot of potentially interesting hits.

      What difference is there between system and qx that will fix path problems?

        I think coldmiser assumed that qx would capture the error message. But it won't, as it'll go out through STDERR. So redirecting 2>&1 on the command line of qx/backticks will probably allow the script to see what is wrong.