Jump to content

Help with run command.


Glyph
 Share

Recommended Posts

Run("cmd.exe /k tracert "&$dahip)

fixed!

It's good that you figured out how to leave the "DOS Box" open so you could read the results. If you would like to access the results programmatically, then you would either redirect the results to a file:
$sTRText = "C:\Temp\TraceRoute.txt"
Run("cmd.exe /c tracert " & $dahip & " > " & $sTRText)

...or capture the output with $STDOUT_CHILD and StdOutRead():

#include <Constants.au3>
#include <Array.au3>

Global $dahip = "127.0.0.1", $sOutput = ""

Global $iPID = Run(@ComSpec & " /c tracert " & $dahip, @TempDir, @SW_MINIMIZE, $STDOUT_CHILD)

While 1
    $sOutput &= StdoutRead($iPID)
    If @error Then ExitLoop
WEnd

; Remove blank lines
$avOutput = StringSplit($sOutput, @CRLF)
For $n = $avOutput[0] To 1 Step -1
    If StringStripWS($avOutput[$n], 8) = "" Then _ArrayDelete($avOutput, $n)
Next
$sOutput = _ArrayToString($avOutput, @CRLF, 1)

; Display result
MsgBox(64, "TraceRt", $sOutput)

:P

P.S. This shows a more efficient way to remove blank lines:

#include <Constants.au3>

Global $dahip = "127.0.0.1", $sOutput = ""

Global $iPID = Run(@ComSpec & " /c tracert " & $dahip, @TempDir, @SW_MINIMIZE, $STDOUT_CHILD)

While 1
    $sOutput &= StdoutRead($iPID)
    If @error Then ExitLoop
WEnd

; Remove blank lines
$sOutput = StringRegExpReplace($sOutput, "\s{2,}", @CRLF)

; Display result
MsgBox(64, "TraceRt", $sOutput)

:P

Edit: Changed "/k" back to "/c" in my examples.

Edited by PsaltyDS
Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...