Mikeman27294 Posted February 5, 2012 Share Posted February 5, 2012 (edited) Hey guys, I have never touched the standard output functions (Other than ConsoleWrite for debugging). At the moment, I am trying to develop a console application (as shown below) which should attach to AutoIT script processes, and show everything read from the standard output of the file. I am aware that Scite has a console (as are most people) but I want to be able to read the standard output of other programs, and feel that this would be a good way to start learning to do so. Here is the code I have done so far: FileWrite(@ScriptDir&"TestScript.au3", "For $Repeat = 0 to 100"&@CRLF&@TAB&'ConsoleWrite("Text_"&$Repeat&@CRLF)'&@CRLF&@TAB&"Sleep(1000)"&@CRLF&"Next") $GUI = GUICreate("Console", @DesktopWidth / 3, @DesktopHeight / 2) $EDT = GUICtrlCreateEdit("", 0, 0, @DesktopWidth / 3, (@DesktopHeight / 2)-25) $BTN = GUICtrlCreateButton("Update", 0, (@DesktopHeight/2)-25, @DesktopWidth/3, 25) GUISetState() $ProcessName = Run(FileGetShortName(@AutoItExe)&" "&@ScriptDir&"TestScript.au3") While 1 $MSG = GuiGetMsg() Switch $MSG Case -3 FileDelete(@ScriptDir&"TestScript.au3") Exit Case $BTN GUICtrlSetData($EDT, StdoutRead($ProcessName)) EndSwitch WEnd Have I done something wrong here? I have been kicking myself over this all day and have gone as far as I can with the help file, and don't know what I am doing wrong. Can somebody give me some pointers please? Thanks. Hahaha this forum works wonders. I figured it out hahaha! I had to run it like this: $ProcessName = Run(FileGetShortName(@AutoItExe)&" "&@ScriptDir&"TestScript.au3", @ScriptDir, @SW_HIDE, $STDERR_CHILD + $STDOUT_CHILD) I tried doing this earlier, but with another script and it didn't work. Well, atleast I have it figured out now. I think earlier, I didn't specify a working directory or something, maybe. Edited February 5, 2012 by Mikeman27294 Link to comment Share on other sites More sharing options...
water Posted February 5, 2012 Share Posted February 5, 2012 Please have a look at the examples in the help file for function "StdOutRead". My UDFs and Tutorials: Spoiler UDFs: Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs: Excel - Example Scripts - Wiki Word - Wiki Tutorials: ADO - Wiki WebDriver - Wiki Link to comment Share on other sites More sharing options...
Mikeman27294 Posted February 5, 2012 Author Share Posted February 5, 2012 (edited) Please have a look at the examples in the help file for function "StdOutRead". Yes, I did all day today and was kicking myself because it worked when I ran the examples, but not when I ran my own one. I decided that it must have been the program I was running (Which I ran as a child process, I'm sure) that wasn't working so I just made a new script, and did a new run function, but forgot the child process tag. It works now, the code is below: #include <Constants.au3> FileDelete(@ScriptDir&"TestScript.au3") FileWrite(@ScriptDir&"TestScript.au3", "Sleep(1000)"&@CRLF&"For $Repeat = 0 to 100"&@CRLF&@TAB&'ConsoleWrite("Text_"&$Repeat&@CRLF)'&@CRLF&@TAB&"Sleep(10)"&@CRLF&"Next") $GUI = GUICreate("Console", 500, 500) $EDT = GUICtrlCreateEdit("", 0, 0, 500, 500) ;~ $BTN = GUICtrlCreateButton("Update", 0, (@DesktopHeight/2)-25, @DesktopWidth/3, 25) $ProcessName = Run(FileGetShortName(@AutoItExe)&" "&@ScriptDir&"TestScript.au3", @ScriptDir, @SW_HIDE, $STDERR_CHILD + $STDOUT_CHILD) $StdOut = "" While ProcessExists($ProcessName) $StdOut &= StdoutRead($ProcessName)&@CRLF WEnd While StringInStr($StdOut, @CRLF&@CRLF) $StdOut = StringReplace($StdOut, @CRLF&@CRLF, @CRLF) WEnd If StringLeft($StdOut, 1) = @CRLF Or StringLeft($StdOut, 1) = @CR or StringLeft($StdOut, 1) = @LF Then $StdOut = StringTrimLeft($StdOut, 1) EndIf If StringRight($StdOut, 1) = @CRLF Or StringRight($StdOut, 1) = @CR Or StringRight($StdOut, 1) = @LF Then $StdOut = StringTrimRight($StdOut, 1) EndIf GUICtrlSetData($EDT, $StdOut) GUISetState() While 1 $MSG = GuiGetMsg() Switch $MSG Case -3 FileDelete(@ScriptDir&"TestScript.au3") Exit EndSwitch WEnd Edited February 5, 2012 by Mikeman27294 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