【问题标题】:PHP - PSExec Output not showingPHP - PSExec 输出未显示
【发布时间】:2015-07-21 10:22:38
【问题描述】:

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

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

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

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

但是,当我从 PHP 运行它时,我只能看到 stderr 提要(发送到屏幕或文件时),但根本看不到 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);
?>

谢谢!

【问题讨论】:

  • 旁注 - 如果我从 cmd 导航到 c:\xampp\php 并运行命令“php.exe filename.php”,那么它会显示标准输出正常(到 cmd 行或到文件),但同样,不是通过网络浏览器运行时。
  • 试试 xcmd - feldkir.ch/xcmd.htm

标签: php batch-file psexec


【解决方案1】:

据我了解,您希望将 stderr 和 stdout 结合起来,以便将 psexec.exe 的所有输出都放在 $output 变量中:

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

如果正确,只需将 2>&1 放在命令末尾

这里是有关重定向标准错误Is there a way to redirect ONLY stderr to stdout (not combine the two) so it can be piped to other programs?的更多信息的链接

【讨论】:

  • 这会产生相同的结果,stderr(psexec 横幅)将显示,但 stdout 仍然无处可见。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2023-03-25
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-04-15
相关资源
最近更新 更多