Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Executing program with arguments from cgi script

by natol44 (Sexton)
on Jan 24, 2021 at 17:27 UTC ( #11127377=perlquestion: print w/replies, xml ) Need Help??

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

Greetings!

I need to run ffmpeg from a CGI script, of course with arguments: Video to process, watermark to add, etc, and output file.

I put all this in one variable:

my $order = "$ffmpeg -i $video -i $watermark parameters etc $output";

with $ffmpeg is the program's address, $video the video address etc.



then I tried with

system "$order";
and
`$order`;

Nothing works.

If I write the output content of $order in the SSH command line, it works.

Where am I wrong? Thank you!
  • Comment on Executing program with arguments from cgi script

Replies are listed 'Best First'.
Re: Executing program with arguments from cgi script
by haukex (Bishop) on Jan 24, 2021 at 17:33 UTC
    I need to run ffmpeg from a CGI script, of course with arguments

    This is a very dangerous thing to do. See Calling External Commands More Safely for why, and for some modules that you could use to make the risk smaller. Assuming this is on a *NIX system, at the very least, you must use the system LIST form, for example system($ffmpeg,'-i',$video,'-i',$watermark,...), and you should additionally validate the variables you're passing to the command.

    Nothing works.

    I suspect there is an error happening that you're not seeing. See the documentation of system on how to check for errors; the same advice from that documentation on inspecting $? applies to backticks as well.

      I finally solved it using system. Risks seem low as the script is working in cron from a non-accessible place from users. Thank you all for your help :)
        Risks seem low

        History is littered with the corpses of those who said just that.

        At least run in taint mode: a low-impact way to remove a lot of the remaining danger.


        🦛

Re: Executing program with arguments from cgi script
by bliako (Prior) on Jan 24, 2021 at 20:01 UTC

    Are you sure the path $ffmpeg is correct? Better write to a log file what command you are running prior to executing the system() to make sure. And then write the exit code to the log file as well. It's possible to obtain the STDOUT, STDERR (see note below by Anonymous Monk) of the system command simply by my $out = `$order`; Start your debugging with that.

    If the path is correct, then there maybe a problem with your parameters, quotation, escape-chars etc. which only appears when running through system(). It could also be that your webserver does not allow to execute system() commands.

    But when you eventually find out what's wrong, take haukex's advice very seriously. This is one of lamest ways to get hacked.

      It's possible to obtain the STDOUT, STDERR of the system command simply by my $out = `$order`;

      backticks only capture STDOUT unless you do 2>&1

        thanks, I haven't paid attention to this important detail.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://11127377]
Approved by haukex
Front-paged by Corion
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (5)
As of 2021-03-04 00:58 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    My favorite kind of desktop background is:











    Results (97 votes). Check out past polls.

    Notices?