如何从 php 传递参数调用 bash 脚本

发布于 2024-09-01 06:11:13 字数 231 浏览 1 评论 0原文

我有一个执行 bash 脚本的 php 脚本。我尝试像这样传递参数:

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

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

出了什么问题?我该如何传递参数?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

彻夜缠绵 2024-09-08 06:11:13

你的点在错误的地方,应该阅读:

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

或更具可读性

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

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

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

or more readable

exec( "$script $file $prefix" );
陌上芳菲 2024-09-08 06:11:13

这是错误的:

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

小心引号:-)

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

this is wrong:

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

be carefull with quotes :-)

exec ($script.' '.$file.' '.$prefix);
浮光之海 2024-09-08 06:11:13

我不太明白你的问题是什么,但你的 exec() 调用应该如下所示:

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

如果你接受来自外部的参数(例如来自 GET 或 POST 参数),请务必使用 escapeshellarg() 出于安全原因在参数上。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文