Sign in to follow this  
Followers 0
Nunos

inputbox and an error

9 posts in this topic

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.

Share this post


Link to post
Share on other sites



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?

Share this post


Link to post
Share on other sites

#5 ·  Posted (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 by Nunos

Share this post


Link to post
Share on other sites

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. :D

Share this post


Link to post
Share on other sites

#9 ·  Posted (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. :D

Edited by Nunos

Share this post


Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0