botanic Posted January 16, 2009 Share Posted January 16, 2009 Is there any easy way to get this? I tried $tmp = RunWait("route print 0.0.0.0") I was just going to format the string however that returns 0 how can I get the text that is normally printed to the command prompt? Link to comment Share on other sites More sharing options...
Andreik Posted January 16, 2009 Share Posted January 16, 2009 Is there any easy way to get this? I tried $tmp = RunWait("route print 0.0.0.0") I was just going to format the string however that returns 0 how can I get the text that is normally printed to the command prompt?Try this: #include <Process.au3> MsgBox(0,"Default Gateway",GetDefaultGateway()) Func GetDefaultGateway() _RunDOS("ipconfig >" & @TempDir & "\gateway.dat") $FILE = FileOpen(@TempDir & "\gateway.dat",0) $INDEX = 1 While 1 $LINE = FileReadLine($FILE,$INDEX) If @error = -1 Then Exit $SPLIT = StringSplit($LINE,":") If IsArray($SPLIT) Then If StringInStr($SPLIT[1],"Default Gateway") <> 0 Then Return StringStripWS($SPLIT[2],4) EndIf $INDEX += 1 WEnd FileClose($FILE) EndFunc When the words fail... music speaks. Link to comment Share on other sites More sharing options...
botanic Posted January 16, 2009 Author Share Posted January 16, 2009 nevermind got it Func _get_default_gateway() $output = _get_cmd_output("netstat -rn") $arr = StringSplit($output, "0.0.0.0", 1) $arr2 = StringStripWS($arr[3], 1) $arr2 = StringSplit($arr2, " ") Return $arr2[1] EndFunc Func _get_cmd_output($cmd) $cmd_timeout = 2000 $pid = Run($cmd,@WorkingDir,@SW_HIDE,2) $timer = TimerInit() while (ProcessExists($pid)) sleep(50) If TimerDiff($timer) > $cmd_timeout Then ProcessClose($pid) WEnd $output = StdoutRead($pid) Return StringStripCR($output) EndFunc 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