【发布时间】:2014-04-28 16:52:51
【问题描述】:
我一直在为此绞尽脑汁和电脑,希望有人能在这里帮助我。
我有一个 PHP 站点,需要执行一个 powershell 脚本,该脚本依次执行和可执行。
调用.ps1的PHP是
define('updaterPath','C:\\artemis\\DbUpdateUtility1.0.12.2');
define('outputLocation',updaterPath.'\\Output');
$CMD = updaterPath . '\\ArtemisXmlUtil.exe';
$action = 'import';
$args= ' -f' . outputLocation;
$psScriptPath = '.\\get-process.ps1';
$query = shell_exec("powershell -command $psScriptPath -cmd '$CMD' -action '$action' -paras '$args' < NUL");
我的 .ps1 脚本是:
param(
[string]$CMD,
[string]$action,
[string]$paras
)
& $CMD $action $paras
现在,当我回显完整命令时,它看起来很完美,可以复制并粘贴到 powershell 中并成功运行,但是当我尝试从 php 实际执行它时,它只使用 $CMD 变量运行并忽略$action 和 $paras。
我尝试将变量全部连接到 1 个字符串中,但由于无法看到可执行文件而失败。
完整的命令应该是这样的:
C:\artemis\DbUpdateUtility1.0.12.2\ArtemisXmlUtil.exe import -fC:\artemis\DbUpdateUtility1.0.12.2\Output
【问题讨论】:
标签: php variables powershell powershell-3.0