Nunos Posted November 26, 2012 Share Posted November 26, 2012 So I wanted to use Guinness's tracert snippet tp prompt for a user to input what they wanted to tracert to but I am unable to even make it work as is below before I even try to sort how to get an inputbox in it. I am getting the following. ERROR: $sOutput previously declared as a 'Const'. $sOutput &= StdoutRead($iPID) ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^ #include ConsoleWrite(_Tracert("www.duckduckgo.com") & @CRLF) Func _Tracert(Const $sURL) ; -d = Do Not Resolve Host & -h Is The Number Of Hops. Local Const $sData = _RunStdOutRead('tracert -d -h 1 ' & $sURL, @SystemDir) Local Const $aReturn = StringRegExp($sData, '\[([\d.]{7,15})\]', 3) If @error Then Return SetError(1, 0, -1) EndIf Return $aReturn[0] EndFunc ;==>_Tracert Func _RunStdOutRead($sCommand, $sWorkingDirectory = @SystemDir) Local Const $iPID = Run(@ComSpec & ' /c ' & $sCommand, $sWorkingDirectory, @SW_HIDE, $STDOUT_CHILD + $STDERR_CHILD), $sOutput = '' While 1 $sOutput &= StdoutRead($iPID) If @error Then ExitLoop EndIf WEnd Return $sOutput EndFunc ;==>_RunStdOutRead If someone could advise me as to what I am doing wrong here I would appreciate the help. I also would like some direction on using an inputbox to get the user to type in a url or ip to tracert too. Firstly do I assign that to the $sURL above? Also is there a way to verify it is an IP address or a url? Thank you in advance. Link to comment Share on other sites More sharing options...
jmon Posted November 26, 2012 Share Posted November 26, 2012 it's because you declared $sOutput as a constant. Constant variables cannot be modified during the execution of the script. just declare it like that: Local $sOutput = "" (Remove the "Const" keyworkd) [center]www.jmontserrat.comFile Sequence UDF - _StringExtractPaths - _StringTrimPattern - GuiCtrlSetOnTop - CalendarUDF[/center] Link to comment Share on other sites More sharing options...
Nunos Posted November 26, 2012 Author Share Posted November 26, 2012 Thank you Jmon that appears to have sorted it. Any thoughts on a decent way to toss an inputbox in there to prompt for IP's and URL's to test? Link to comment Share on other sites More sharing options...
jmon Posted November 26, 2012 Share Posted November 26, 2012 did you try to add an input box at the beginning of your script? check out "InputBox" in the help file. Then use whatever the user input as the string to search in _Tracert [center]www.jmontserrat.comFile Sequence UDF - _StringExtractPaths - _StringTrimPattern - GuiCtrlSetOnTop - CalendarUDF[/center] Link to comment Share on other sites More sharing options...
Nunos Posted November 26, 2012 Author Share Posted November 26, 2012 (edited) Not sure what to assign it to and then how to send it to the msgbox instead of console. I am not great at scripting if you can't tell. I made the InputBox and assigned it to $trace then added that to the console write but I don't think this is right and I would really like to somehow get the output to say like a message box or similar. Thank you for your time and I appologize if I sound like a complete noob. #include Local $trace = InputBox("Tracert", "Please enter a url or IP address to test.", "www.bing.com") ConsoleWrite(_Tracert($trace) & @CRLF) Func _Tracert(Const $sURL) ; -d = Do Not Resolve Host & -h Is The Number Of Hops. Local Const $sData = _RunStdOutRead('tracert -d -h 1 ' & $sURL, @SystemDir) Local Const $aReturn = StringRegExp($sData, '[([d.]{7,15})]', 3) If @error Then Return SetError(1, 0, -1) EndIf Return $aReturn[0] EndFunc ;==>_Tracert Func _RunStdOutRead($sCommand, $sWorkingDirectory = @SystemDir) Local $iPID = Run(@ComSpec & ' /c ' & $sCommand, $sWorkingDirectory, @SW_HIDE, $STDOUT_CHILD + $STDERR_CHILD), $sOutput = '' While 1 $sOutput &= StdoutRead($iPID) If @error Then ExitLoop EndIf WEnd Return $sOutput EndFunc ;==>_RunStdOutRead Edited November 27, 2012 by Nunos Link to comment Share on other sites More sharing options...
jmon Posted November 27, 2012 Share Posted November 27, 2012 Replace ConsoleWrite(_Tracert($trace) & @CRLF) by MsgBox(0, "This is the returned value", _Tracert($trace)) [center]www.jmontserrat.comFile Sequence UDF - _StringExtractPaths - _StringTrimPattern - GuiCtrlSetOnTop - CalendarUDF[/center] Link to comment Share on other sites More sharing options...
Nunos Posted November 27, 2012 Author Share Posted November 27, 2012 Thank You JMon. Works fine but it only returns one IP I was thinking it would return all of the hops. Not sure if I can get it to send all of the information back from the cmd window or not but no biggy if not. I appreciate your help. Link to comment Share on other sites More sharing options...
jmon Posted November 27, 2012 Share Posted November 27, 2012 if you want all the return from the command line, then in _tracert, return $sData instead of $aReturn[0]. $sData contains all the command line return. [center]www.jmontserrat.comFile Sequence UDF - _StringExtractPaths - _StringTrimPattern - GuiCtrlSetOnTop - CalendarUDF[/center] Link to comment Share on other sites More sharing options...
Nunos Posted November 27, 2012 Author Share Posted November 27, 2012 (edited) Awesome thank you. I will see if I can work out how to make that work and let you know. Update: It's working great thank you for your time and patience JMon. Edited November 27, 2012 by Nunos 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