Jump to content

STDIN STDOUT STDERR Problem


Recommended Posts

This is quite probably not an AutoIt issue, I'm just hoping that someone here can point me in the right direction.

I can't get ssh to work via stdin/out/err redirection. This is just a proof of concept for a more complicated project.

Here's the most simplified example. Its a basic terminal in autoit.

It runs most commands without issue (apart from a few formatting problems that I haven't tried to fix)

The problem comes when I try to ssh into a machine, or rsync (via ssh)

I've tried using tcsh (my preferred shell) and CMD.exe, I can't get either to work.

No doubt I'm missing something simple. I'd appreciate any tips you guys may have.

Also, if someone could give me a tip on a more efficient way of adding the output to the editbox it would be helpful.

[EDIT]Just found a small extra nugget of information. It works with passwordless shh.

Unfortunately thats not gonna cut it for my needs :D

CODE
#include <GUIConstants.au3>

#Include <GuiEdit.au3>

Opt("OnExitFunc", "OnExit")

FileChangeDir ( "C:\cygwin\bin" )

; USE ONLY ONE OF THE 2 LINES BELOW

$cygwin = Run( "tcsh -i","C:\cygwin\bin",@SW_HIDE,7) ; UNCOMMENT TO USE tcsh.exe

;$cygwin = Run( @comspec,"",@SW_HIDE,7) ; UNCOMMENT TO USE @comspec

;stdinWrite($cygwin, "ls" & " " & @CRLF)

$form = GUICreate("Test",500,500)

$ediCMD=GUICtrlCreateEdit ("",0,0,500,470,$ES_WANTRETURN+$WS_VSCROLL+$ES_AUTOVSCROLL)

GUICtrlSetBkColor ( $ediCMD,000)

GUICtrlSetColor ( $ediCMD,255255255)

GUICtrlSetState($ediCMD,$GUI_DISABLE)

$inpCMD=guictrlcreateinput ("",0,470,500,30)

GUISetState ()

While 1

$msg = GUIGetMsg()

If $msg = $GUI_EVENT_CLOSE Then ExitLoop

Switch $msg

Case $inpCMD

$inputtext = GUICtrlRead($inpCMD)

GUICtrlSetData($inpCMD,"")

stdinWrite($cygwin, $inputtext & " " & @CRLF)

EndSwitch

ReadStdout()

ReadStderr()

Wend

Func OnExit()

ProcessClose($cygwin)

Exit

EndFunc

Func ReadStdout()

$iCharsToRead = StdoutRead($cygwin,0,True)

If $iCharsToRead > 0 Then

$sText = "stdout-" & StdoutRead($cygwin,$iCharsToRead)

$sText = StringReplace($sText,@LF,@CRLF)

$sExistingData = GUICtrlRead($ediCMD)

GUICtrlSetData($ediCMD, $sExistingData & $sText)

_GUICtrlEdit_Scroll($ediCMD, $SB_SCROLLCARET)

Endif

EndFunc

Func ReadStderr()

$iCharsToRead = StderrRead($cygwin,0,True)

If $iCharsToRead > 0 Then

$sText = "stderr-" & StderrRead($cygwin,$iCharsToRead)

$sText = StringReplace($sText,@LF,@CRLF)

$sExistingData = GUICtrlRead($ediCMD)

GUICtrlSetData($ediCMD, $sExistingData & $sText)

_GUICtrlEdit_Scroll($ediCMD, $SB_SCROLLCARET)

Endif

EndFunc

Edited by kev51773
Link to comment
Share on other sites

I've messed around for a while and the problem is that these password prompts don't seem to be stdout or stderr.

For example, when I type 'ssh user@127.0.0.1 >& test' the password prompt is still displayed in the terminal.

I realise now, that this isn't an Autoit problem, but I'd still appreciate any suggestions.

Link to comment
Share on other sites

I've messed around for a while and the problem is that these password prompts don't seem to be stdout or stderr.

For example, when I type 'ssh user@127.0.0.1 >& test' the password prompt is still displayed in the terminal.

I realise now, that this isn't an Autoit problem, but I'd still appreciate any suggestions.

Upon using " >& " to redirect the stream, I get an error of ">& was not expected at this time". Note that I did the test without using SHH. I can also just guess that "test" is a file without an extension?

If you are going to redirect to a file then I would expect using " > test". To redirect StdErr to StdIn as an example of using the handle operator "&", then use " 2>&1 test" (2 is the StdErr flag and &1 is the StdIn handle).

:D

Link to comment
Share on other sites

Upon using " >& " to redirect the stream, I get an error of ">& was not expected at this time". Note that I did the test without using SHH. I can also just guess that "test" is a file without an extension?

If you are going to redirect to a file then I would expect using " > test". To redirect StdErr to StdIn as an example of using the handle operator "&", then use " 2>&1 test" (2 is the StdErr flag and &1 is the StdIn handle).

:D

Yes 'test' is a file without an extension (sorry I'm generally more linux oriented). All of the examples I posted were examples I typed into a cygwin tcsh terminal. 'ssh user@127.0.0.1 >& test' was just a test typed into a cygwin tcsh terminal to see if I could cause the password prompt to be redirected to anything other than the terminal. I figure if I can't even redirect it to a file, I've got no chance of getting autoit to read it.

I'm guessing that you were running some shell other than tcsh when you did the test as '>&' should be correct for tcsh.

I've tried every variation I can think of to redirect this output to STDOUT, I've even tried redirecting handles 3-9 in case it was using them. I've no idea how its managing to display text without using any accessible stream.

Link to comment
Share on other sites

Yes 'test' is a file without an extension (sorry I'm generally more linux oriented). All of the examples I posted were examples I typed into a cygwin tcsh terminal. 'ssh user@127.0.0.1 >& test' was just a test typed into a cygwin tcsh terminal to see if I could cause the password prompt to be redirected to anything other than the terminal. I figure if I can't even redirect it to a file, I've got no chance of getting autoit to read it.

I'm guessing that you were running some shell other than tcsh when you did the test as '>&' should be correct for tcsh.

I've tried every variation I can think of to redirect this output to STDOUT, I've even tried redirecting handles 3-9 in case it was using them. I've no idea how its managing to display text without using any accessible stream.

All sorted, I managed to read the prompt from memory. Hardly an ideal solution, but it works solidly. :D

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...