HansHenrik Posted May 30, 2020 Share Posted May 30, 2020 (edited) this is the ConsoleRead signature: ConsoleRead ( [peek = False [, binary = False]] ) and here is ConsoleWrite: ConsoleWrite ( "data" ) and ConsoleWrite will stop writing on the first null byte, i think ConsoleWrite should get a (optional) binary mode like ConsoleRead, ConsoleWrite ( "data" [, binary = False] ) - while it is possible to create a binary ConsoleWrite in userland, it's more difficult (and slower, and more memory hungry, making a full copy of the data before writing) than it should be, imo, my implementation: ; binary safe ConsoleWrite() ( AutoIt's builtin ConsoleWrite() is not binary safe, it chokes if you try to write a null byte to stdout) Func ConsoleWriteBinary( $str) Local $bytesWritten=0; Local $stdoutHandle=_WinAPI_GetStdHandle(1); Local $tBuffer = DllStructCreate("byte[" & StringLen($str) & "]"); DllStructSetData($tBuffer, 1, $str); _WinAPI_WriteFile ( $stdoutHandle, $tBuffer, StringLen($str), $bytesWritten); return $bytesWritten; EndFunc (idk if there's a better way to do it, but even if there's a better way, there wouldn't be any need if ConsoleWrite had a binary mode) Edited April 30, 2021 by HansHenrik remove Const ByRef Link to comment Share on other sites More sharing options...
HansHenrik Posted May 30, 2020 Author Share Posted May 30, 2020 (edited) why was this moved to "sample scripts" ? this thread isn't about sample scripts, i'm requesting an enhancement of a core AutoIt function =/ Edited May 30, 2020 by HansHenrik Link to comment Share on other sites More sharing options...
Danp2 Posted May 30, 2020 Share Posted May 30, 2020 If a thread is moved, usually a mod will indicate why. Could you have accidentally posted in the wrong section? Either way, just use the "report post" feature and request that it get moved to the proper forum. Latest Webdriver UDF Release Webdriver Wiki FAQs Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted May 30, 2020 Moderators Share Posted May 30, 2020 HansHenrik, If you want to request a new feature in AutoIt, please open a Trac ticket. As it is you have provided a UDF as a work-around and so the thread was moved to the Examples section which is where such things should be posted. M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
HansHenrik Posted May 30, 2020 Author Share Posted May 30, 2020 i see, thanks. made a "Trac ticket", https://www.autoitscript.com/trac/autoit/ticket/3764 Link to comment Share on other sites More sharing options...
Skysnake Posted May 30, 2020 Share Posted May 30, 2020 @HansHenrik I can see the application, but what stops you from using something like ConsoleWrite("String as HEX " & Hex($var) & @CRLF) Skysnake Why is the snake in the sky? Link to comment Share on other sites More sharing options...
argumentum Posted May 30, 2020 Share Posted May 30, 2020 ...at times you may want to have a CUI and not stop due to a NULL or something. Makes sense. #Region ;**** Directives created by AutoIt3Wrapper_GUI **** #AutoIt3Wrapper_Change2CUI=y #EndRegion ;**** Directives created by AutoIt3Wrapper_GUI **** #include <WinAPIHObj.au3> If Not @Compiled Then Exit MsgBox(262144, @ScriptName, "for this to showcase the code, run compied.", 60) Global $test=""; for $i = 0 To 255 $test = $test & Chr($i); Next $test &= @CRLF ConsoleWrite("Test # 1: ""ConsoleWrite()""" & @CRLF); ConsoleWrite($test); ConsoleWrite("Test # 2: ""ConsoleWriteBinary()""" & @CRLF); ConsoleWriteBinary($test); ConsoleWrite("Done." & @CRLF); sleep(2000) ; binary safe ConsoleWrite() ( AutoIt's builtin ConsoleWrite() is not binary safe, it chokes if you try to write a null byte to stdout) Func ConsoleWriteBinary( Const ByRef $str) Local $bytesWritten=0; Local $stdoutHandle=_WinAPI_GetStdHandle(1); Local $tBuffer = DllStructCreate("byte[" & StringLen($str) & "]"); DllStructSetData($tBuffer, 1, $str); _WinAPI_WriteFile ( $stdoutHandle, $tBuffer, StringLen($str), $bytesWritten); return $bytesWritten; EndFunc Follow the link to my code contribution ( and other things too ). FAQ - Please Read Before Posting. Link to comment Share on other sites More sharing options...
HansHenrik Posted May 30, 2020 Author Share Posted May 30, 2020 (edited) 2 hours ago, Skysnake said: @HansHenrik I can see the application, but what stops you from using something like ConsoleWrite("String as HEX " & Hex($var) & @CRLF) sometimes writing it in hex is not sufficient. let's say you want to implement the Unix Cat program in AutoIt ( https://en.wikipedia.org/wiki/Cat_(Unix) ), a program available on all Linux and MacOS systems, but not shipped with Windows, without thinking too much about it, i would probably write it as: ; PS! this code is *intentionally* bugged, do you see the bug? ; PS! this code must be compiled with Aut2exe.exe with the /console argument! ; first read stdin Local $stdinData While True $stdinData = ConsoleRead(False,True); If @error Then ExitLoop If(StringLen($stdinData) == 0) Then ExitLoop ConsoleWrite($stdinData); WEnd ; then read all files in arguments For $i = 1 To $cmdLine[0] Step 1 ConsoleWrite(FileRead($cmdLine[$i])); Next simple enough, right? but the code has a bug (maybe it has more than 1 bug, but it has *at least* 1 bug, that i see) do you see the bug? Edited May 30, 2020 by HansHenrik compile instructions Link to comment Share on other sites More sharing options...
Skysnake Posted May 31, 2020 Share Posted May 31, 2020 I see. But... Is this a matter of using the right tool for the job? Is this a bug or was AutoIt simply never intended to do this? Skysnake Why is the snake in the sky? Link to comment Share on other sites More sharing options...
argumentum Posted June 2, 2020 Share Posted June 2, 2020 NULLs have a history, so that is that. As far as ConsoleWrite a NUL, I guess no one care to use it the way he will. I too use PHP with AutoIt but I use TCP due to the overhead of loading an EXE as CGI. But even if the Ticket don't get adopted, the function he wrote is good to have. The $str is not modified so it will not be added twice in AutoIt's memory, so the "Const ByRef $str" can be dropped, adding flexibility to the function. HansHenrik 1 Follow the link to my code contribution ( and other things too ). FAQ - Please Read Before Posting. Link to comment Share on other sites More sharing options...
HansHenrik Posted August 31, 2020 Author Share Posted August 31, 2020 On 5/31/2020 at 1:18 PM, Skysnake said: I see. But... Is this a matter of using the right tool for the job? Is this a bug or was AutoIt simply never intended to do this? well.. "The AutoIt language was never intended to be flexible enough to allow implementations of programs such as Unix Cat" doesn't really sound right to me, but after reading "Jpm"'s response to https://www.autoitscript.com/trac/autoit/ticket/3764 , maybe you're actually right Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now