Jump to content

GUI Edit box not processing CRLF from Run StdoutRead


mcBeth
 Share

Recommended Posts

Version: (3.3.8.1) AU3Check (1.54.22.0) AutoIt3Wrapper v.2.0.1.24

Hello,

Why is text coming from a StdoutRead stream not correctly formatted in an Editbox?

Thx in adv

Im building a GUI to simultaneously Run multiple instances of a putty plink command.

The outputstream should be captured in separated Editboxes.

Output of finished sessions will be copied to a "merge" Editbox.

To get started I used koda building a simple GUI framework and added the provided example: Demonstrates StdoutRead() [stdoutRead.au3] and changed the command to be run plink....

By running this concept a msgbox is shown with descend formatting.

Then I added GUICtrlSetData() to capture the content in an Editbox

Running the mod. the CR & LF are ommitted in the Editbox

If I selectAll & copy/paste the text into an editor all CR & LF are still there.

This is the testingScript

#include <Constants.au3>
#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <GuiEdit.au3>

Opt("GUIOnEventMode", 1)

$Form1 = GUICreate("Form1", 479, 237, 192, 114)
GUISetOnEvent($GUI_EVENT_CLOSE, "Form1Close")

$edtStream1 = GUICtrlCreateEdit("", 0, 0, 377, 105)
GUICtrlSetData(-1, "edtStream")
GUICtrlSetFont(-1, 8, 400, 0, "Courier New")

$edtStream2 = _GUICtrlEdit_Create( $Form1, "", 0, 120, 377, 105)
_GUICtrlEdit_SetText( $edtStream2, "edtMerge")

$btnStart = GUICtrlCreateButton("btnStart", 392, 32, 75, 25)
GUICtrlSetOnEvent(-1, "btnStartClick")

GUISetState(@SW_SHOW)

While 1
Sleep(100)
WEnd

Func btnStartClick()
runCommand()
EndFunc

Func Form1Close()
Exit
EndFunc

Func runCommand ()
Local $foo = Run(@ComSpec & " /c plink -ssh sshSession2Celerra -m " & @ScriptDir & "\cmds_ls_tmp.txt", @ScriptDir, @SW_HIDE, $STDERR_CHILD + $STDOUT_CHILD)
Local $line
While 1
$line = StdoutRead($foo)
If @error Then ExitLoop
MsgBox(0, "STDOUT read:", $line)
GUICtrlSetData( $edtStream1, $line, 1 )
_GUICtrlEdit_AppendText( $edtStream2, $line )
WEnd

While 1
$line = StderrRead($foo)
If @error Then ExitLoop
; MsgBox(0, "STDERR read:", $line)
GUICtrlSetData( $edtStream1, $line, 1 )
WEnd

MsgBox(0, "Debug", "Exiting...")
EndFunc
Link to comment
Share on other sites

mcbeth. it might have to do with the font and size.

i use this when using stdoutread to output to an editbox.

GUICtrlSetFont(-1, 10, 400, 0, "Lucida Console")

the spacing of certain fonts i noticed do not output stdoutread to edit box because the editbox supports a higher set of fonts and such like notepad., a 'mono' spaced font like Lucida Console should

output without any weirdness, like a regular cmd console box. the font sizing is pt 10. 8 is nice, but i like 10.

Edited by pixeldotz
Link to comment
Share on other sites

Thank's for your reply pixeldotz

I've tried several font settings, even an OEMCONVERT but alas, none of them worked out right.

I wonder if this is a bug.

Even StringSplit() doesn't recognize the @CRLF.

otherwise _ArrayDisplay() would have displayed every line in a separate array cel

Putting a different delimiter into StringSplit(), _ArrayDisplay() does show multiple cel's

Local $arr = StringSplit( $line, "a7", 1 )
_ArrayDisplay( $arr )

I'm still puzzled

Link to comment
Share on other sites

I used the DIR command in place of Plink and it worked for me with your script as is. It might be an issue with Plink and not with AutoIt. You can always append a @CRLF to the end or beginning of the $line variable before putting it into the Edit box.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

Thank's for your reply BrewManNH

Indeed running a native command will format correctly (I tried a few). And yes, one could blame it to plink.exe

In that case, one could blame it to any NONE native WindowsCommandShell command. :huh:

e.g. Build a console app, run it, and check the result.

I just wanted to see it for myself did it with this autoIT code:

#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_Change2CUI=y
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****

# ConsoleReadWrite.exe
#include <String.au3>

Local $data
While True
$data &= ConsoleRead()
If @error Then ExitLoop
Sleep(25)
WEnd

Local $upper = _StringReverse( $data )
ConsoleWrite( $upper & @CRLF )

I changed my testing script line saying:

Local $foo = Run(@ComSpec & " /c plink -batch -ssh sshSession2Celerra -m " & @ScriptDir & "\cmds_ls_tmp.txt", @ScriptDir, @SW_HIDE, $STDERR_CHILD + $STDOUT_CHILD)

in to:

Local $foo = Run(@ComSpec & " /c dir | "& @ScriptDir & "\ConsoleReadWrite.exe " , @ScriptDir, @SW_HIDE, $STDERR_CHILD + $STDOUT_CHILD)

And again, the @CRLF's are omitted in the Editbox

So, okay: NONE native WindowsCommandShell commands are not handled well by GUICtrlSetData() and StringSplit() except for the MsgBox()

The more I think of it the more the suspect arises MsgBox() uses a different autoIT_class responsible for the IO handling than GUICtrlSetData() and StringSplit(). MsgBox() always displayed the IO stream by StdoutRead() nicely formatted.

I hope somebody has an eureka :D

Thanks in advance

Link to comment
Share on other sites

I tried your test script and it wasn't working right with the edit control. I then tried everything I could think of to see why it wouldn't work, because I use this exact same technique in a script I have used for a couple of years now with an edit control and it works perfectly.

One of the tests I did was to take out the StringReverse part of the test script and then recompiled it, and it worked for me without that. So, I don't think it is the Edit control, or the way AutoIt reads from the StdOut streams, I think that issue was with the StringReverse function. I still think it's an issue with plink and not with AutoIt, because no matter what program I test (that outputs to the console) it works for me.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

Whoops, I ran out of the 5 credits [You can make 0 posts until 20 September 2012 - 12:24 PM.]

You will have to wait as this is a measure in place to stop spamming of new accounts. Please don't create a new account to bypass this. See Forum Rules as to why I said that.

UDF List:

 
_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_ArrayFilter/_ArrayReduce_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 22/04/2018

Link to comment
Share on other sites

OT:

You will have to wait as this is a measure in place to stop spamming of new accounts. Please don't create a new account to bypass this. See Forum Rules as to why I said that.

1st of all: I respect the rules. it's the 1st thing I read before I commit myself to them. One could claim just anything ;)

Though it wouldn't harm welcoming if a fresh member with your note and telling what to expect next. e.g. restrictions you mentioned and how long these last.

OT-END

Having said that, I proudly announce the solution to this topic.

I discovered that plink.exe marks it's EOL by a single LF control char.

Apparently MsgBox() takes a LF or CR or CRLF for granted

as for GUICtrlCreateEdit() requires specifically CRLF

So all that is needed is a function that, "Takes a string and prefixes all linefeed characters ( Chr(10) ) with a carriage return character ( Chr(13) )"

Cool! you guy's knew that all along cos that Func exists: StringAddCR()

One thing left to say:

how come Func _StringReverse() didn't act right?

Well it reversed the CRLF control char instead of leaving them alone. and therefor a LF was put before CR

Well, that's about it.

Bottom line: I now know the topic should have read: GUI Edit box not processing LF

I humble request the manual writers to add a note to the FAQ and Func: GUICtrlCreateEdit() and StdoutRead() pointing out this feature and link StringAddCR() to the Related.

Thx 2 @

Edited by mcBeth
Link to comment
Share on other sites

1st of all: I respect the rules. it's the 1st thing I read before I commit myself to them. One could claim just anything

Though it wouldn't harm welcoming if a fresh member with your note and telling what to expect next. e.g. restrictions you mentioned and how long these last.

I don't know when the restriction ends, else I would have told you. It wasn't meant to be an aggressive message as you might have taken it, just so many new people create an account to bypass the restriction and this causes unnecessary hassle for the Mods. Anyway, glad you took note of the Forum Rules. You will go far here!

UDF List:

 
_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_ArrayFilter/_ArrayReduce_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 22/04/2018

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...