繁体   English   中英

在Powershell上执行php脚本

[英]Executing php script on powershell

美好的一天!

我有一个powershell代码,我想在最后运行一个php脚本。 我曾尝试寻找解决方案,但似乎无法碰到任何东西。 我所能找到的就是通过批处理文件运行php脚本。 使用Powershell运行php脚本,这可能吗? 如果是这样,怎么办?

使用呼叫运算子( & ):

# 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

我尝试使用上面的@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

希望它可以帮助某人:)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM