AndyS01 Posted April 22, 2013 Share Posted April 22, 2013 I have a function that uses Run() to run a "nslookup" command and check to see if the address passed to it is reachable. After invoking the Run() command, I use calls to StderrRead() to read nslookup's output. I'm able to see the output, but it also displays in AutoIT's console output window (F8). I would like to keep nslookup's output from showing up in AutoIT's output window because I use ConsoleWrite() to output progress messages. I tried redirecting nslookup's output to a file, but nslookup complained. Here is some test code:_NS_Lookup("www.google.com") Func _NS_Lookup($ip) Local $ret, $str $ret = Run("nslookup " & $ip , @SystemDir, @SW_HIDE, 4) $str = "" While 1 $str &= StderrRead($ret) If @error Then ExitLoop WEnd If (StringInStr($str, "can't find " & $ip)) Then $ret = False Else $ret = True EndIf Return ($ret) EndFunc ;==>_NS_Lookup Link to comment Share on other sites More sharing options...
Nessie Posted April 22, 2013 Share Posted April 22, 2013 (edited) Try this: #include <Constants.au3> $NSLookupURL = InputBox("NSLookup", "Enter the URL to perform the Name Server Lookup on.", "www.bing.com") $Result = _NS_Lookup($NSLookupURL) If $Result = True Then MsgBox(0, "Debug", $NSLookupURL & " is reachable") Else MsgBox(0, "Debug", $NSLookupURL & " isn't reachable") EndIf Func _NS_Lookup($ip) Local $OutLine Local $nslookup = Run(@ComSpec & " /c nslookup " & $NSLookupURL, @SystemDir, @SW_HIDE, $STDIN_CHILD + $STDERR_MERGED) While 1 $line = StdoutRead($nslookup) If @error Then ExitLoop $OutLine &= $line WEnd ;MsgBox(0, "Debug", $OutLine) If (StringInStr($OutLine, "can't find " & $ip)) Then $ret = False Else $ret = True EndIf Return ($ret) EndFunc ;==>_NS_Lookup HI! Edited April 22, 2013 by Nessie My UDF: NetInfo UDF Play with your network, check your download/upload speed and much more! YTAPI Easy to use YouTube API, now you can easy retrive all needed info from a video. NavInfo Check if a specific browser is installed and retrive other usefull information. YWeather Easy to use Yahoo Weather API, now you can easily retrive details about the weather in a specific region. No-IP UDF Easily update your no-ip hostname(s). My Script: Wallpaper Changer Change you wallpaper dinamically, you can also download your wallpaper from your website and share it with all! My Snippet: _ImageSaveToBMPConvert an image to bmp format. _SciteGOTO Open a file in SciTE at specific fileline. _FileToHex Show the hex code of a specified file Link to comment Share on other sites More sharing options...
JohnOne Posted April 22, 2013 Share Posted April 22, 2013 Run(@ComSpec & "nslookup " & $ip , @SystemDir, @SW_HIDE, 4) AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans. Link to comment Share on other sites More sharing options...
Mobius Posted April 22, 2013 Share Posted April 22, 2013 (edited) Run(@ComSpec & "nslookup " & $ip , @SystemDir, @SW_HIDE, 4)@comspec macro is not required to run console based applications, this method is abused so often in this forum it is tragic, why because it saves you having to differentiate between cmd.exe native commands and those that are executable files?If you didn't use it then your code line would not have the bug it currently has. Edited April 22, 2013 by Mobius Link to comment Share on other sites More sharing options...
JohnOne Posted April 22, 2013 Share Posted April 22, 2013 If I'm honest, I've never used it until I just tested it then and it gave desired result. AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans. Link to comment Share on other sites More sharing options...
Mobius Posted April 22, 2013 Share Posted April 22, 2013 (edited) If I'm honest, I've never used it until I just tested it then and it gave desired result.If you had copy and pasted then run what you posted the only result would have been an invalid exe path error.The point is that yes the method works (else it would not be considered a method to use for so bleeding long) but running two programs where one is sufficient isn't clever or recommendable.Not ragging on just you dude, not really your fault, apart from your use of it actually caused you to post non working code which was otherwise a sound suggestion.Anyway rant over going back into cold storage.Vlad Edited April 22, 2013 by Mobius Link to comment Share on other sites More sharing options...
JohnOne Posted April 22, 2013 Share Posted April 22, 2013 Furry nuff. Mobius 1 AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans. Link to comment Share on other sites More sharing options...
AndyS01 Posted April 22, 2013 Author Share Posted April 22, 2013 I used the code that Nessie provided and it worked like I wanted it to (thank you very much). How would you change that code to run without @comspec? Link to comment Share on other sites More sharing options...
AndyS01 Posted April 22, 2013 Author Share Posted April 22, 2013 Actually, I changed the Run line to look like this and it worked OK: $ret = Run("nslookup " & $ip, @SystemDir, @SW_HIDE, $STDIN_CHILD + $STDERR_MERGED) Link to comment Share on other sites More sharing options...
AndyS01 Posted April 22, 2013 Author Share Posted April 22, 2013 The solution was to pass the "$STDERR_MERGED" flag and to read from StdOut. Link to comment Share on other sites More sharing options...
Nessie Posted April 22, 2013 Share Posted April 22, 2013 Glad to help you;) My UDF: NetInfo UDF Play with your network, check your download/upload speed and much more! YTAPI Easy to use YouTube API, now you can easy retrive all needed info from a video. NavInfo Check if a specific browser is installed and retrive other usefull information. YWeather Easy to use Yahoo Weather API, now you can easily retrive details about the weather in a specific region. No-IP UDF Easily update your no-ip hostname(s). My Script: Wallpaper Changer Change you wallpaper dinamically, you can also download your wallpaper from your website and share it with all! My Snippet: _ImageSaveToBMPConvert an image to bmp format. _SciteGOTO Open a file in SciTE at specific fileline. _FileToHex Show the hex code of a specified file 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