【问题标题】:PHP shell_exec multiple commands with system variables?PHP shell_exec 带有系统变量的多个命令?
【发布时间】:2021-03-02 17:05:44
【问题描述】:

我正在尝试通过 PHP 的 shell_exec 执行多个互连的 shell 命令,这些命令具有变量(系统级加密任务的一部分),但无法获得我期望的输出。这是shell命令:

text=outputofsomething.bash
echo $(echo -n $text | openssl dgst -sha256 -sigopt rsa_padding_mode:pss <etc>)

在命令行上运行它可以正常工作,在 shell_exec 中运行它会给出一个空字符串。

$shell_comm = <<<BASH
    text=outputofsomething.bash;echo $(echo -n $text | openssl dgst -sha256 -sigopt rsa_padding_mode:pss <etc>)
BASH;
var_dump(shell_exec($shell_comm));

【问题讨论】:

    标签: php shell-exec


    【解决方案1】:

    也许可以试试这样的:

    text=outputofsomething.bash
    exec("echo -n $text | openssl dgst -sha256 -sigopt rsa_padding_mode:pss <etc> 2>&1", $output, $return);
    
    $complete_output = '';
    if (!empty($output)) {
        foreach ($output as $value) {
            $complete_output .= "$value" . PHP_EOL;
        }
    }
    
    echo $complete_output;
    

    【讨论】:

    • 但是如何在我正在执行的内容中包含“text=outputofsomething.bash”?
    • @Wige:您能否提供更多当前代码的示例,直到text=outputofsomething.bash
    猜你喜欢
    • 2016-07-16
    • 2011-03-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-08-22
    相关资源
    最近更新 更多