I tried
[ autoIt ] ( Popup )
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?
Posted 16 January 2009 - 10:33 PM
botanic, on Jan 17 2009, 12:23 AM, said:
#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
Posted 16 January 2009 - 10:35 PM
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