美好的一天!
我有一个powershell代码,我想在最后运行一个php脚本。我试图寻找解决方案,但我似乎无法碰到任何问题。我所能找到的只是通过批处理文件运行php脚本。使用PowerShell运行php脚本,这可能吗?如果是这样,怎么样?
答案 0 :(得分:1)
使用呼叫运算符(&
):
# Set up references to executable and script
$PhpExe = "C:\path\to\php\install\dir\php.exe"
$PhpFile = "C:\path\to\script.php"
# Create arguments from Script location
# usually php.exe is invoked from console like:
# php.exe -f "C:\path\myscript.php"
$PhpArgs = '-f "{0}"' -f $PhpFile
# Invoke, using the call operator
$PhpOutput = & $PhpExe $PhpArgs
答案 1 :(得分:1)
我尝试使用@Mathias R. Jessens上面的答案,但它对我不起作用,原因是$PhpArgs = '-f "{0}"' -f $PhpFile
包含第一个'-f'
部分。所以使用他的答案(以及对我有用的是)
# Set up references to executable and script
$PhpExe = "C:\path\to\php\install\dir\php.exe"
$PhpFile = "C:\path\to\script.php"
# Create arguments from Script location
# usually php.exe is invoked from console like:
# php.exe -f "C:\path\myscript.php"
$PhpArgs = '"{0}"' -f $PhpFile //Changed this line!
# Invoke, using the call operator
$PhpOutput = & $PhpExe $PhpArgs
希望它可以帮助某人:)