nabrugir
nabrugir

Reputation: 1869

How to call a bash script from php passing parameters

I have a php script that execute a bash script. I try to pass parameters like this:

$script="/opt/lampp/htdocs/adapt.sh"
$file="/opt/lampp/htdocs/videos/video1.mp4"
$prefix="Test"

exec ('.$script.' '.$file.' '.$prefix.');

What's wrong? How can I pass the parameters?

Upvotes: 4

Views: 6698

Answers (3)

Pekka
Pekka

Reputation: 449395

I dont really understand what your question is, but your exec() call should look like this:

exec ($script.' '.$file.' '.$prefix);

If you accept parameters from outside (e.g. from a GET or POST parameter), be sure to use escapeshellarg() on the arguments for security reasons.

Upvotes: 1

acm
acm

Reputation: 6637

this is wrong:

exec ('.$script.' '.$file.' '.$prefix.');

be carefull with quotes :-)

exec ($script.' '.$file.' '.$prefix);

Upvotes: 1

Jan Gorman
Jan Gorman

Reputation: 1006

You have your dots in the wrong place, should read:

exec ( $script . ' ' . $file . ' ' . $prefix );

or more readable

exec( "$script $file $prefix" );

Upvotes: 3

Related Questions