dinodod Posted September 14, 2013 Share Posted September 14, 2013 I am trying to debug why the StderrRead() keeps hanging up in my script. I've tried using the timerdiff() to aid me but it hasn't been able to work since the StderrRead() gets hung up. Is there some way to keep this from happening? Thank you! Func _ReverseDNS($IPAddress) Local $NSLookupCmd,$ResponseText,$X1,$X2 $IPAddress = StringStripWS($IPAddress,3) $NSLookupCmd = Run(@ComSpec & " /c nslookup "& $IPAddress, "", @SW_HIDE, $STDOUT_CHILD+$STDERR_CHILD) $a = TimerInit() While 1 If TimerDiff($a) > 10000 Then ConsoleWrite("End of Loop" & @CRLF) ExitLoop ; 10000 = 10 seconds EndIf StderrRead($NSLookupCmd) If @error Then ExitLoop WEnd $ResponseText = StdoutRead($NSLookupCmd) If @error Then Return $x1 = StringInStr($ResponseText, "Name:") $x2 = StringInStr($ResponseText, "Address",0,-1) If $x1 > 0 and $x2 > 0 Then Return StringStripWS(StringMid($ResponseText, $x1 + 6, $x2 - $x1 - 6),3) Return "Unknown" EndFunc Digital Chaos - Life as we know it today.I'm a Think Tank. Problem is, my tank is empty.The Quieter you are, the more you can HearWhich would you choose - Peace without Freedom or Freedom without Peace?Digital Chaos Macgyver ToolkitCompletely Dynamic MenuSQLIte controlsAD FunctionsEXCEL UDFPC / Software Inventory UDFPC / Software Inventory 2GaFrost's Admin Toolkit - My main competitor :)Virtual SystemsVMWAREMicrosoft Virtual PC 2007 Link to comment Share on other sites More sharing options...
Solution BrewManNH Posted September 14, 2013 Solution Share Posted September 14, 2013 The very first thing I would do is to remove both the /c and the @SW_HIDE from your run command line. Why do you have it closing and hidden before you even get it working right? You should leave the console window open so you can read any errors you might receive. Once you know the script is working as you want it to, then you can start getting fancy with the window. Second, remove the StdErrRead line and modify your While/Wend loop to something like this. $a = TimerInit() While ProcessExists($NSLookupCmd) If TimerDiff($a) > 10000 Then ConsoleWrite("End of Loop" & @CRLF) ExitLoop ; 10000 = 10 seconds EndIf Sleep(100) WEnd $ResponseText = StdoutRead($NSLookupCmd) If @error Then ReturnYou can still read the StdOut after the process has closed so this is a quick and easy way of reading it all at once, and there's no need to check the StdErr stream to see if it errors out. 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 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