PHP - PSExec输出未显示

时间:2015-07-21 10:22:38

标签: php batch-file psexec

我认为这与this question相同,但未提供解决方案。

我有一个查询,它使用PSExec在配置文件服务器上进行网络会话,当从命令行输入时,它可以正常工作:

psexec \\profile-server -u username -p password net session

它将显示PSExec横幅(来自stderr),然后显示查询结果(来自stdout)。

但是,当我从PHP运行时,我只能看到stderr feed(发送到屏幕或文件时),但根本看不到stdout。当我将stdout重定向到文件时,文件为空。

这是PHP:

<?php
    $uname_prof = "DOMAIN-USERNAME";
    $pw_prof = "DOMAIN-PASSWORD";
    $ip = "PROFILE-SERVER";

    $query = "psexec.exe \\\\$ip -u $uname_prof -p $pw_prof net session";

    $result = exec($query, $output);

    echo implode('<br>', $output);
?>

谢谢!

1 个答案:

答案 0 :(得分:0)

据我所知你想组合stderr和stdout所以你在$ output变量中得到了psexec.exe的所有输出:

$query = "psexec.exe \\\\$ip -u $uname_prof -p $pw_prof net session 2>&1";

如果这是正确的,只需在命令末尾加上2&gt;&amp; 1

这里是有关redirect stderr Is there a way to redirect ONLY stderr to stdout (not combine the two) so it can be piped to other programs?

的更多信息的链接