Monacco Franze Monacco Franze - 2 months ago 28
PHP Question

Execute powershell command via php

I have the following problem:

I hava a xampp sever running and I want it to execute a powershell. A php triggers a .bat file which contains the following code:

cd C:\OpenBR\bin
start /WAIT br -algorithm FaceRecognition -compare C:\xampp\htdocs\upload C:\xampp\htdocs\DP C:\xampp\htdocs\results\result.csv

start /WAIT C:\xampp\htdocs\CSVconvert\sortieren.ps1

start /WAIT C:\xampp\htdocs\CSVconvert\Removedouble.ps1

start /WAIT C:\xampp\htdocs\CSVconvert\remove_path.ps1

start /WAIT C:\xampp\htdocs\CSVconvert\remove_foo.ps1

start C:\xampp\htdocs\CSVconvert\remove_quoatation.ps1

The first part works fine, up until the point when i want to exec the powershell "sortieren.ps1". When I run the batch manually, it executes and does the job, when triggered via php, it doesn't.
I set "Set-ExecutionPolicy Unrestricted" in both x86 and x64 shells.
I am just confused because the normal command line works and powershell doesn't, even after setting it on unrestricted.

I viewed
executing a Powershell script from php
PowerShell on Windows 7: Set-ExecutionPolicy for regular users
but couldn't solve the problem.
What did i miss?


The session you are running those commands in doesn't have the same environment variables as when you are using PowerShell to run them manually. You'll have to specify the absolute path to the powershell executeable and the scripts that you want to run so that they will be found.

start /WAIT C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe C:\xampp\htdocs\CSVconvert\sortieren.ps1