Menu

#4 Output from a command after pipe fails to display (.bat too)

closed-fixed
nobody
None
5
2011-06-15
2011-05-26
No

When winexe passes a sequence of commands with a pipe character to a given host, the output of the command is supressed or otherwise mis-directed and fails to display. This happens even when the commands are within a batch file on the host system which is then executed by winexe.

* Contents of batch file:
@echo "you can only see this!"
@echo "can you not see this?" | find /i "see this"

* Psexec command (executing batch script):
psexec \\windowsbox -h -u test -p "testpass" cmd /c "c:\windows\temp\foo.bat"

* Psexec output (executing batch script):
"you can see this!"
"can you not see this?"

* Winexe command (executing batch script):
winexe --debug-stderr -U 'test%testpass' //windowsbox 'cmd /c c:\windows\temp\foo.bat'

* Winexe output (executing batch script):
"you can only see this!"

When not trying to execute a batch file, but directly passing the pipe in the command and using findstr instead of find, something interesting happens that might give a hint as to the root cause of this:

* Psexec command (pass pipe directy):
psexec \\windowsbox -h -u test -p "testpass" cmd /c "echo "this" | findstr "this""

* Psexec output (pass pipe directy):
"this"

* Winexe command (pass pipe directy):
winexe --debug-stderr -U 'test%testpass' //windowsbox 'cmd.exe /c echo "this" | findstr "this"'

* Winexe output (pass pipe directy):
FINDSTR: Write error

I've tested this with several types of target host (Windows Server 2003 R2, Windows XP Pro) and from various types of winexe hosts (Mac OS X 10.6.7, Ubuntu 10.04, Fedora 14) and with three versions of Winexe (0.80, 0.90, 0.91).

Discussion

  • Thomas Hood

    Thomas Hood - 2011-06-15

    I found the bug. The problem is that in the present winexe code a single pipe is used for both standard input and standard output of the remotely executed process. Effectively the standard input is used also as the standard output. Now suppose a child process inherits the parent's pipes and its standard input get replaced by a pipe coming from another child process. Oops, its standard output has also been overwritten by something that it can't write to.

    I have fixed this by modifying winexe.c and winexesvc.c so that separate pipes are used for standard input and standard output.

    The patch against the current winexe git tree can be downloaded here: http://trac.openpcf.org/attachment/wiki/Winexe/winexe-pipe-bugfix_20110615-1.diff

    Testing:

    $ bin/winexe --debug-stderr -U 'test%testpass' //windowsbox 'cmd /c echo this'
    this
    $ bin/winexe --debug-stderr -U 'test%testpass' //windowsbox 'cmd /c echo this | sort'
    this
    $ bin/winexe --debug-stderr -U 'test%testpass' //windowsbox 'cmd /c echo this | findstr this'
    this
    $ bin/winexe --debug-stderr -U 'test%testpass' //windowsbox 'cmd /c echo this | findstr xyzzy'
    $ bin/winexe --debug-stderr -U 'test%testpass' //windowsbox 'cmd /c type \t.bat'
    @echo "you can only see this!"
    @echo "can you not see this?" | find /i "see this"
    $ bin/winexe --debug-stderr -U 'test%testpass' //windowsbox 'cmd /c \t.bat'
    "you can only see this!"
    "can you not see this?"
    $ bin/winexe --version
    Version 4.0.0alpha11-GIT-UNKNOWN

     
  • ahajda

    ahajda - 2011-06-15

    Patch applied, thanks.

     
  • ahajda

    ahajda - 2011-06-15
    • status: open --> closed-fixed
     

Log in to post a comment.

MongoDB Logo MongoDB