通过php执行powershell命令 [英] Execute powershell command via php
问题描述
我有以下问题:
我正在运行一个xampp服务器,我希望它执行Powershell. php会触发一个.bat文件,其中包含以下代码:
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:
@echo
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
第一部分工作正常,直到我要执行powershell"sortieren.ps1"为止.当我手动运行批处理时,它会执行并执行工作,通过php触发时,它不会执行. 我在x86和x64 Shell中都设置了"Set-ExecutionPolicy Unrestricted". 我只是感到困惑,因为即使将其设置为无限制,普通命令行也无法正常运行,而powershell却无法运行.
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.
我查看了 从php执行Powershell脚本 和 Windows 7上的PowerShell:普通用户的Set-ExecutionPolicy 但无法解决问题. 我想念什么?
I viewed executing a Powershell script from php and PowerShell on Windows 7: Set-ExecutionPolicy for regular users but couldn't solve the problem. What did i miss?
推荐答案
运行这些命令的会话与使用PowerShell手动运行它们的环境变量不同.您必须指定可执行Powershell的绝对路径以及要运行的脚本,以便找到它们.
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
这篇关于通过php执行powershell命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!