【问题标题】:How can i pass a program name throgh php to a to a shell script file?如何通过 php 将程序名称传递给 shell 脚本文件?
【发布时间】:2015-01-22 17:07:13
【问题描述】:

通过 HTML 文件,我将文件名发送到运行 shell 脚本的位置。我想将该文件名作为参数发送到 shell 脚本。 $prg1=$_POST['prg1']; 我从用户输入导入的这个文件。 shell_exec('./shell.sh') 在这个脚本中我想发送那个文件。 有什么帮助吗?

【问题讨论】:

    标签: php html shell


    【解决方案1】:

    使用escapeshellarg 添加适当的引用,然后将其作为参数连接到脚本。

    shell_exec('./shell.sh ' . escapeshellarg($prg1));
    

    然后脚本可以将参数设为$1

    对于多个参数,用空格隔开:

    shell_exec('./shell.sh ' . escapeshellarg($prg1) . ' ' . escapeshellarg($prg2) . ' ' . escapeshellarg($prg3) );
    

    【讨论】:

    • 传递多个参数的语法是什么? @Barmar
    • 在命令行中用空格分隔它们,就像在 shell 中键入一样。
    猜你喜欢
    • 2023-04-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-04-03
    • 2015-08-30
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多