0

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?

2 Answers 2

1

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
Sign up to request clarification or add additional context in comments.

Comments

1

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 :)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.