首页 > 解决方案 > 如何执行 shell_exec 命令

问题描述

我实际上正在使用 POST 变量来执行 PowerShell 脚本的 PHP 脚本。但不知何故,脚本没有启动。

我用 shell_exec 尝试了很多东西:-切换引号-更改脚本的路径,但没有任何改变:/

<?php
    //Shell_Exec ('powershell.exe -executionpolicy bypass -NoProfile -Command "Get-Process | ConvertTo-Html"');
    //storaging the variables passed by POST
    $LastName = $_POST["LastName"];
    $FirstName = $_POST["FirstName"];
    $type = $_POST["type"];
    $begin = $_POST["begin"];
    $end = $_POST["end"];
    $desc = $_POST["desc"];
    $command = shell_exec('./Script.ps1 -FirstName "'.$FirstName.'" -LastName "'.$LastName.'" -Description "'.$desc.'" -Type "'.$type.'" -AGOL $true ');
?>

执行此操作应该会生成一个 PDF 文件,但没有任何结果。我的 shell_exec 正确吗?谢谢你的帮助!

标签: phphtmlpowershell

解决方案


    $command = shell_exec('powershell ./Script.ps1 -FirstName "'.$FristName.'" -LastName "'.$LastName.'" -Description "'.$desc.'" -Type "'.$type.'" -AGOL $true ');

将 附加powershell到函数的开头shell_exec应该会产生您想要的结果。


推荐阅读