PHP exec不';t返回外部程序的输出

PHP exec不';t返回外部程序的输出,php,windows,exec,Php,Windows,Exec,我有以下计划: function execute_query($ip, $username, $password, $query){ $runCMD ="python run_query.py " . escapeshellarg($ip). " ". escapeshellarg($username) . " " . escapeshellarg($password) . ' ' . escapeshellarg($query); $output = [];

我有以下计划:

function execute_query($ip, $username, $password, $query){
    $runCMD ="python run_query.py " . escapeshellarg($ip). " ". escapeshellarg($username) . " " . escapeshellarg($password)
        .  ' ' . escapeshellarg($query);
    $output = [];
    exec ($runCMD, $output);
    print_r ($output);
    //return (implode("\n", $output));
}
但是,数组$output始终为空,当从CMD手动执行时,程序将正确返回结果。我不知道该怎么办。我试了很多东西,甚至都记不起来了。以下是一些:

1.I disable UAC
2.I tried using shell_exec
3.I tried appending powershell in front of the command 'powershell' . $runCmd
4.I tried appending '2>&1' at the end of the command
5.I tried using proc_open, to manually open cmd.exe and execute the command
任何其他想法我可以做什么,或者至少如何继续故障排除。使用Linux不是一种选择 看来stderr正在工作。我还试着从python脚本中打印“asd”,它可以正常工作。 python脚本的输出是WMI查询,它可能包含\n、\r和\t

以下是python脚本:

from subprocess import check_output
import sys

def run_query(ip, username, password, query):
    runCMD = "query.exe " + username + " " + password + ' "' + query + '" ' + ip + ''
    results = check_output(runCMD).decode("utf-8")
    results = results.split("\n")
    for result in results:  
        if not result.startswith("__"):
            print(result)
if __name__ == "__main__":
    run_query(sys.argv[1], sys.argv[2], sys.argv[3], sys.argv[4])
更新1
query.exe是一个程序,它返回WMI查询的筛选结果,并作为参数传递。不知道里面是什么,但它按预期工作。我还尝试从php脚本运行query.exe,同样的事情是没有输出。
更新2
我使用的是PHP7.1,没有运气就尝试了PHP5.6。
更新3
在python中尝试将字符串更改为字节数组时,手动运行脚本时会得到以下输出:

bytearray(b'The RPC server is unavailable. (Exception from HRESULT: 0x800706BA)\r')
bytearray(b'')
,但php脚本返回以下内容:

Array
(
    [0] => bytearray(b'')
)

更新4

f***it我正在将整个项目切换到python

您可能应该尝试使用绝对路径,并在python脚本中添加一些调试,以验证它是否首先被调用。我也尝试使用绝对路径,但忘了提及它。现在,我将在python脚本中添加几行代码—似乎正在调用python脚本。另外,如果我试图从python脚本打印'asd',它将被PHP应用程序捕获?你们的问题中并没有提到这一点。不,它实际上是登录到文件中的。目前我在python脚本中犯了一个错误,它将其打印出来。我不知道stderr现在可以工作了。您可能应该尝试使用绝对路径,并在python脚本中添加一些调试,以验证它是否正在被调用。我也尝试过使用绝对路径,但忘了提及它。现在,我将在python脚本中添加几行代码—似乎正在调用python脚本。另外,如果我试图从python脚本打印'asd',它将被PHP应用程序捕获?你们的问题中并没有提到这一点。不,它实际上是登录到文件中的。目前我在python脚本中犯了一个错误,它将其打印出来。我不知道stderr现在能用了