I just made a function to run a shell command and grab the output. It comes with a modified version of _TempFile:
; ----------------------------------------------------------------------------
;
; AutoIt Version: 3.1.0
; Author: B. Daams <brammeleman@brammeleman.org>
;
; Script Function:
; Execute a single DOS command and return stdout
;
; Example:
; Msgbox(4096, "Output of 'ls' on a remote host:", _ShellExec("c:\progra~1\putty\plink.exe host ls"))
; ----------------------------------------------------------------------------
Func _ShellExec($cmd)
$batchtemp = _TempFile2("bat")
$resulttemp = _TempFile2("txt")
; add " > $resulttemp" to $cmd
$cmd = $cmd & "> " & $resulttemp
; write $cmd to $batchtemp
$fh = FileOpen ($batchtemp,2)
If $fh = -1 Then
MsgBox(0, "Error", "Unable to open temporary batch file for writing.")
Exit
EndIf
FileWrite($fh, $cmd)
FileClose($fh)
; run $batchtemp
RunWait($batchtemp, @TempDir, @SW_HIDE)
; read $resulttemp to $returnval
$fh = FileOpen($resulttemp, 0)
; Check if file opened for reading OK
If $fh = -1 Then
MsgBox(0, "Error", "Unable to open result file.")
Exit
EndIf
; Read in lines of text until the EOF is reached
$returnval = ""
While 1
$returnval = $returnval & @LF & FileReadLine($fh)
If @error = -1 Then ExitLoop
Wend
; clean up the mess
FileDelete($batchtemp)
FileDelete($resulttemp)
return $returnval
EndFunc
Exit
Func _TempFile2($ext = "tmp")
; slightly modified version of UDF _TempFile
; this function accepts an optional argument $ext which
; allows you to specify the file type for the temporary
; file
Local $s_TempName
Do
$s_TempName = "~"
While StringLen($s_TempName) < 8
$s_TempName = $s_TempName & Chr(Round(Random(97, 122), 0))
Wend
$s_TempName = @TempDir & "\" & $s_TempName & "." & $ext
Until Not FileExists($s_TempName)
Return ($s_TempName)
EndFunc