Good Day!
I have a powershell code and I would like to run a php script at the very end. I have tried searching for solutions but I can't seem to bump on any. All I could find is to run php script through a batch file. Running a php script using powershell, Is this possible? If so, how?
Use the call operator ( &
):
# 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
I tried using @Mathias R. Jessens answer above but it wouldn't work for me, the reason was the $PhpArgs = '-f "{0}"' -f $PhpFile
contained the first '-f'
part. So using his answer (and what worked for me was)
# 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
Hope it helps someone :)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.