Jump to content

output format from console to editbox and consolewrite


nicknuke
 Share

Recommended Posts

I am creating a simple one liner command to ssh server so "normal" user can do one simple task from their windows machine
without command line, just a plain gui and a click of a button.
I've managed to get it work so far ( taking scripts from this awesome forum, tbh.. )
The problem is when i test it, it can dump the output just fine on output panel in autoit ( consolewrite ),
but when i redirect it to an editbox, the format is awfull... 

Would anyone care to help me with how to format the output on editbox to be the same like consolewrite output ?
the script snippet is here :

 

$answer = _runSshCommand($unixUser, $unixHost, $sshCommand, $unixPassword)
            ConsoleWrite($answer)
            GUICtrlSetData($Edit1,$answer & @CRLF)


And the output is here, both consolewrite and editbox..


Thank you in advance ..




 

editbox-output.png

Link to comment
Share on other sites

20 minutes ago, Nine said:

Just set the edit box to a fixed size font ?

No go :(  
I tried your suggestion right away, and set editbox font to fixedsys monospace font.. 
the output is still messed up .. :(

Koda's simple gui :

 

$Form1 = GUICreate("Form1", 826, 695, 571, 248)
$Edit1 = GUICtrlCreateEdit("", 368, 56, 393, 553, BitOR($ES_AUTOHSCROLL,$WS_HSCROLL,$WS_VSCROLL,$WS_BORDER), $WS_EX_STATICEDGE)
;GUICtrlSetData(-1, "Edit1")
GUICtrlSetFont(-1, 8, 400, 0, "Fixedsys")
$showleasebtn = GUICtrlCreateButton("Show Lease", 104, 96, 99, 33)
GUISetState(@SW_SHOW)

 

Clipboard01.jpg

Edited by nicknuke
Link to comment
Share on other sites

Link to comment
Share on other sites

On 2/21/2022 at 12:53 AM, Nine said:

Copy the output to a notepad file and attach that file here.  Make a small snippet of your edit box so we can test it here, reading the file.  

I changed the command to a simple "ls -l <directory> on linux machine, the result is pretty much the same..
It even has "quite right" display when it's being output to msgbox..
here are all the snip and snaps.. I dumped the output to editbox,msgbox, and consolewrite..
 

#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 835, 634, 622, 236)
$Edit1 = GUICtrlCreateEdit("", 240, 24, 577, 561,BitOR( $ES_WANTRETURN, $WS_VSCROLL, $WS_HSCROLL, $ES_AUTOVSCROLL, $ES_AUTOHSCROLL, $ES_READONLY))
GUICtrlSetData(-1, "Edit1")
$showleasebtn = GUICtrlCreateButton("ls -l", 56, 72, 107, 33)
$restartbtn = GUICtrlCreateButton("Restart DHCP", 54, 146, 107, 33)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

Here is the main call :

 

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $showleasebtn
            $sshCommand = "ls -l /home/wolf/"
            $answer = _runSshCommand($unixUser, $unixHost, $sshCommand, $unixPassword)
            ConsoleWrite($answer)
            GUICtrlSetData($Edit1,$answer & @CRLF)
            MsgBox(0,"SSH Output", $answer)
        ;Case $Edit1
    EndSwitch
WEnd

 

Thanks in advance...

 

21 hours ago, Zedna said:

I think that problem is LF as end of line in your output but for EditBox you need CRLF.

Could it be ? Because editbox expected DOS command output CRLF,  while the linux/unix ssh terminal output only produce LF ?
If that's true.. that's a bummer for me then 😐

 

editbox-output2.png

output-autoit.txt

Edited by nicknuke
Link to comment
Share on other sites

Well the data you gave me is probably not the one you get from.  Because it working fine with me...

#include <Constants.au3>
#include <GUIConstants.au3>
#include <FontConstants.au3>

$Form1 = GUICreate("Form1", 835, 634, 622, 236)
$Edit1 = GUICtrlCreateEdit("", 240, 24, 577, 561,BitOR( $ES_WANTRETURN, $WS_VSCROLL, $WS_HSCROLL, $ES_AUTOVSCROLL, $ES_AUTOHSCROLL, $ES_READONLY))
GUICtrlSetFont(-1, 10, $FW_NORMAL, $GUI_FONTNORMAL, "Lucida Console")
$showleasebtn = GUICtrlCreateButton("Read txt", 56, 72, 107, 33)
GUISetState(@SW_SHOW)

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $showleasebtn
            $answer = FileRead("output-autoit.txt")
            GUICtrlSetData($Edit1,$answer & @CRLF)
            MsgBox(0,"SSH Output", $answer)
    EndSwitch
WEnd

image.png.67b45d3a00344e26c8c44b2dc47e5a84.png

Try to put the data directly into a file with something like this :

FileWrite("Test.txt", _runSshCommand($unixUser, $unixHost, $sshCommand, $unixPassword))

So I can get the real data you obtain...

output-autoit.txt

 

Edited by Nine
Link to comment
Share on other sites

8 hours ago, Nine said:

Well the data you gave me is probably not the one you get from.  Because it working fine with me...

#include <Constants.au3>
#include <GUIConstants.au3>
#include <FontConstants.au3>

$Form1 = GUICreate("Form1", 835, 634, 622, 236)
$Edit1 = GUICtrlCreateEdit("", 240, 24, 577, 561,BitOR( $ES_WANTRETURN, $WS_VSCROLL, $WS_HSCROLL, $ES_AUTOVSCROLL, $ES_AUTOHSCROLL, $ES_READONLY))
GUICtrlSetFont(-1, 10, $FW_NORMAL, $GUI_FONTNORMAL, "Lucida Console")
$showleasebtn = GUICtrlCreateButton("Read txt", 56, 72, 107, 33)
GUISetState(@SW_SHOW)

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $showleasebtn
            $answer = FileRead("output-autoit.txt")
            GUICtrlSetData($Edit1,$answer & @CRLF)
            MsgBox(0,"SSH Output", $answer)
    EndSwitch
WEnd

image.png.67b45d3a00344e26c8c44b2dc47e5a84.png

Try to put the data directly into a file with something like this :

FileWrite("Test.txt", _runSshCommand($unixUser, $unixHost, $sshCommand, $unixPassword))

So I can get the real data you obtain...

output-autoit.txt 307 B · 0 downloads

 



Yes.. your idea of send the output to file helps. ( Sorry i sent you the wrong text file before.. :D )
I finally managed to spot the problem, pretty much like what Zedna said..

 

On 2/22/2022 at 4:02 AM, Zedna said:

I think that problem is LF as end of line in your output but for EditBox you need CRLF.

 

the editbox expected CRLF'ed input.. while the output from ssh server is just LF..
If I dump the output like you said like this :

 

FileWrite("Test.txt", _runSshCommand($unixUser, $unixHost, $sshCommand, $unixPassword))


and check the Test.txt, the format detected as Unix Text (LF)..
I have to convert it to DOS Text (CRLF) first.., then re-read the file in to editbox..
Then only after that i got perfect output..
I re-send you the original Unix text.. i hope it doesn't get converted automatically here...
It supposed to show you the same garbled text on editbox.


Thank you very much for the clues...
So next question is.. :D
What should I do to make the editbox receive the output in realtime , without putting it to a file and convert first ?


 

 

editbox-output3.png

LF-Format.jpg

Test-UnixText.txt

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