MattHiggs Posted June 7, 2019 Posted June 7, 2019 Hello all. So I have a very peculiar issue. I have wriiten an autoit script which utilizes an external command line utility called http-ping which, as the name would suggest, is able to determine if the web page associated with a given url is online or not. Furthermore, it is very similar in functionality to the regular ping command: Below is a simplified version of the script: expandcollapse popup; *** Start added by AutoIt3Wrapper *** #include <AutoItConstants.au3> ; *** End added by AutoIt3Wrapper *** #Region ;**** Directives created by AutoIt3Wrapper_GUI **** #AutoIt3Wrapper_Add_Constants=n #EndRegion ;**** Directives created by AutoIt3Wrapper_GUI **** #cs ---------------------------------------------------------------------------- AutoIt Version: 3.3.15.0 (Beta) Author: myName Script Function: Template AutoIt script. #ce ---------------------------------------------------------------------------- ; Script Start - Add your code below here #include <ButtonConstants.au3> #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> #Region ### START Koda GUI section ### Form= $Form1 = GUICreate("Form1", 336, 301, 192, 124) $Input1 = GUICtrlCreateInput("", 24, 40, 153, 21) $Label1 = GUICtrlCreateLabel("website", 48, 8, 91, 28) GUICtrlSetFont(-1, 14, 400, 0, "MS Sans Serif") $Button1 = GUICtrlCreateButton("Ping", 200, 40, 73, 25, $BS_NOTIFY) GUICtrlSetState(-1, $GUI_DISABLE) $Edit1 = GUICtrlCreateEdit("", 32, 96, 273, 177, BitOR($ES_AUTOVSCROLL,$ES_AUTOHSCROLL,$ES_READONLY,$ES_WANTRETURN)) GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### While 1 If StringRegExp ( GUICtrlRead ( $Input1 ), "^(http|https)://(www\.)?.+\.\w+(/.*)?$" ) = 1 Then If GUICtrlGetState ( $Button1 ) = 144 Then GUICtrlSetState ( $Button1, $GUI_ENABLE ) EndIf Else If GUICtrlGetState ( $Button1 ) = 80 Then GUICtrlSetState ( $Button1, $GUI_DISABLE ) EndIf EndIf $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $Input1 Case $Button1 GUICtrlSetData ( $edit1, "" ) GUICtrlSetState ( $Button1, $GUI_DISABLE ) $string = "" $proc = Run ( @TempDir & "\httpping.exe " & GUICtrlRead ( $Input1 ), @TempDir, @SW_HIDE, $STDOUT_CHILD ) Do $string = $string & StdoutRead ( $proc ) GUICtrlSetData ( $Edit1, $string ) Until Not ProcessExists ( $proc ) GUICtrlSetState ( $Button1, $GUI_ENABLE ) EndSwitch WEnd As you can see, the script is supposed to set the text of the edit control to the output of the command while the command is running. But it isn't doing that. Instead, it is waiting until the command is finished executing (as if I had called Porcesswaitclose) and then updates the edit control with the command's output: So, to try and troubleshoot what was going on, I modified the script above by changing this line: $proc = Run ( @TempDir & "\httpping.exe " & GUICtrlRead ( $Input1 ), @TempDir, @SW_HIDE, $STDOUT_CHILD ) To this: ;Input an ip address that is valid for your environment $proc = Run ( "ping.exe 192.168.2.2", @TempDir, @SW_HIDE, $STDOUT_CHILD ) To see if the regular ping command acted the same way, which, as you can see, it did not: Why the difference in behavior? I know that I am using a third party command line tool, but I still would have thought that it would behave similarly to other command line tools...... Any info would be appreciated.
BrewManNH Posted June 7, 2019 Posted June 7, 2019 Add this line after the StdoutRead command and see what the output from the program is. ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $string = ' & $string & @CRLF & '>Error code: ' & @error & @CRLF) ;### Debug Console For me, it only sent anything to Stdout after it had finished. Looks like that's the way the program is written. 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 GudeHow 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
jchd Posted June 7, 2019 Posted June 7, 2019 That depends on the external program using buffered or unbuffered stdout, or I/O streams in general. It's an option offered at file open in many libraries but for instance C99 considers stream buffering to be implementation-dependant, unless special measures are taken. This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe hereRegExp tutorial: enough to get startedPCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta. SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)
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