Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/239.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/postgresql/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php exec(';script.ps1';)返回错误,cmd>;scrtipt.ps1运行成功_Php_Postgresql_Powershell_Odbc - Fatal编程技术网

Php exec(';script.ps1';)返回错误,cmd>;scrtipt.ps1运行成功

Php exec(';script.ps1';)返回错误,cmd>;scrtipt.ps1运行成功,php,postgresql,powershell,odbc,Php,Postgresql,Powershell,Odbc,我有一个小的PowerShell脚本来获取远程磁盘空间并将其保存到Postgre DB上的表中 如果我在windows cmd上执行该命令,它将成功运行 C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -File C:\xampp\....\skripts\getDiskSpace.ps1 -Command -arg 192.168.178.178 但是如果我使用PHP exec()函数,我会得到一个odbc错误 exec("

我有一个小的PowerShell脚本来获取远程磁盘空间并将其保存到Postgre DB上的表中

如果我在windows cmd上执行该命令,它将成功运行

C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -File C:\xampp\....\skripts\getDiskSpace.ps1 -Command -arg 192.168.178.178
但是如果我使用PHP exec()函数,我会得到一个odbc错误

exec("C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\powershell.exe -File C:\\xampp\\....\\skripts\\getDiskSpace.ps1 -Command -arg 192.168.178.178", $output);

如果使用PHP escapeshellarg()函数,exec()的$output为NULL


$output的内容是:

[Microsoft][ODBC驱动程序管理器]未找到数据源名称,并且没有 指定的默认驱动程序

我不知道为什么,我用

$conn = New-Object System.Data.Odbc.OdbcConnection
$conn.ConnectionString = "Driver={PostgreSQL Unicode(x64)};Server=$dbServer;Port=5432;Database=$dbName;Uid=$dbUser;Pwd=$dbPass;"
已安装PostgreSQL x64 ODBC驱动程序

我在一台Windows2008SP2企业服务器上工作……(想拿回一台LinuxWebServer:D…)


有人有这样的问题吗?或者知道解决方案吗?

这是一个允许PHP获取真实Powershell并与之动态交互的项目。在这里获取:

下载后,您只需使用以下代码:

$shellObj    = \MTS\Factories::getDevices()->getLocalHost()->getShell('powershell');

$strCmd1   = 'get-WmiObject win32_logicaldisk';
$return1   = $shellObj->exeCmd($strCmd1);
返回将从powershell返回或返回错误命令,就像您坐在控制台上一样。然后在PHP中解析它并插入


此外,您可以针对$shellObj发出任何您喜欢的命令,该环境在PHP脚本的整个生命周期中都得到维护。因此,不要将命令捆绑在脚本文件中,只需使用exeCmd()方法逐个发出命令,这样您还可以处理返回和任何异常。

以下是一个允许PHP获取真实Powershell并与之动态交互的项目。在这里获取:

下载后,您只需使用以下代码:

$shellObj    = \MTS\Factories::getDevices()->getLocalHost()->getShell('powershell');

$strCmd1   = 'get-WmiObject win32_logicaldisk';
$return1   = $shellObj->exeCmd($strCmd1);
返回将从powershell返回或返回错误命令,就像您坐在控制台上一样。然后在PHP中解析它并插入

此外,您可以针对$shellObj发出任何您喜欢的命令,该环境在PHP脚本的整个生命周期中都得到维护。因此,不要将命令捆绑在脚本文件中,只需使用exeCmd()方法逐个发出命令,这样您还可以处理返回和任何异常