php - 如何执行 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 正确吗?谢谢你的帮助!
解决方案
$command = shell_exec('powershell ./Script.ps1 -FirstName "'.$FristName.'" -LastName "'.$LastName.'" -Description "'.$desc.'" -Type "'.$type.'" -AGOL $true ');
将 附加powershell
到函数的开头shell_exec
应该会产生您想要的结果。
推荐阅读
- php - 抑制特定类型的 PhpStorm 检查
- .net-core - 在 Microsoft Bot framework V4 中从 Bot 向用户发送 Excel 文件
- javascript - 如何使用 MS Fluent UI 进行国际化/本地化
- java - 供应商接受方法中的Java泛型不兼容类型
- asp.net - ASP.NET Gridview - bootstrap 4 隐藏列
- powershell - 使用powershell增加包号
- javascript - Javascript画布drawImage结果为空白?-修改-
- javascript - 当我更改旋转 CSS 属性时,我的图像消失了
- c++ - 为什么“***堆栈粉碎检测到***:
终止中止(核心转储)”错误显示在此代码中? - python - 使用 pdfplumber 难以解析 PDF 文件