0

I believe this is the same as this question but no solution was provided.

I have a query which uses PSExec to do a net session ona profile server, and it works fine when put in from the command line like below:

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

It will show the PSExec banner (from stderr) and then the query results (from stdout).

However, when I run this from PHP I can only see the stderr feed (both when sending to the screen or to file) but can't see stdout at all. When I redirect stdout to a file the file is blank.

Here is the 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);
?>

Thanks!

Community
  • 1
  • 1
joshnik
  • 438
  • 1
  • 5
  • 15
  • A side comment - from the cmd if I navigate to c:\xampp\php and run the command "php.exe filename.php" then it shows the stdout fine (either to cmd line or to file) but, again, not when run through a web browser. – joshnik Jul 21 '15 at 10:28
  • try with xcmd - http://feldkir.ch/xcmd.htm – npocmaka Jul 21 '15 at 11:17

1 Answers1

0

as I understand you want to combine stderr and stdout so you have all the output from psexec.exe in the $output variable:

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

if that's right just put 2>&1 at the end of your command

here is link with more info about redirect stderr Is there a way to redirect ONLY stderr to stdout (not combine the two) so it can be piped to other programs?

Community
  • 1
  • 1
reneblue
  • 48
  • 7
  • This yields the same results, the stderr (psexec banner) will show but the stdout is still nowhere to be seen. – joshnik Jul 21 '15 at 10:53