Meinst du das in etwa so?
Redirect
AutoIt
;-- TIME_STAMP 2017-04-02 18:39:32 v 0.1
#include <AutoItConstants.au3>
#include <MsgBoxConstants.au3>
Global $g_iPID, $g_sOutput, $g_sCMD = 'Dir /B /AD ' & @UserProfileDir
_Read_CMD_Output()
_Redirect_CMD_OutputToFile()
_Redirect_CMD_OutputToEditor()
Func _Read_CMD_Output()
$g_iPID = Run(@ComSpec & " /c " & $g_sCMD, '', @SW_HIDE, $STDERR_CHILD + $STDOUT_CHILD)
$g_sOutput = "StdoutRead_____________" & @CRLF
While 1
$g_sOutput &= StdoutRead($g_iPID)
If @error Then ExitLoop ; Exit the loop if the process closes or StdoutRead returns an error.
WEnd
$g_sOutput &= @CRLF & @CRLF & "StderrRead_____________" & @CRLF
While 1
$g_sOutput &= StderrRead($g_iPID)
If @error Then ExitLoop ; Exit the loop if the process closes or StderrRead returns an error.
WEnd
MsgBox($MB_SYSTEMMODAL, "Stdout Read / Stderr Read:", $g_sOutput)
EndFunc
Func _Redirect_CMD_OutputToFile()
; Redirect StdoutRead & StderrRead --> 2>&1>
; https://technet.microsoft.com/en-us/library/bb490982.aspx
RunWait(@ComSpec & " /c " & $g_sCMD & ' 2>&1> ' & @TempDir & '\CMDOUT.txt', '', @SW_HIDE, $STDERR_CHILD + $STDOUT_CHILD)
$g_sOutput = "'FileRead(@TempDir & '\CMDOUT.txt')" & @CRLF & @CRLF
$g_sOutput &= FileRead(@TempDir & '\CMDOUT.txt')
MsgBox($MB_SYSTEMMODAL, "Stdout Read / Stderr Read:", $g_sOutput)
; delete the file
FileDelete(@TempDir & '\CMDOUT.txt')
EndFunc
Func _Redirect_CMD_OutputToEditor()
RunWait(@ComSpec & " /c " & $g_sCMD & ' 2>&1> ' & @TempDir & '\CMDOUT.txt', '', @SW_HIDE, $STDERR_CHILD + $STDOUT_CHILD)
; Open the file in our default editor
ShellExecute(@TempDir & '\CMDOUT.txt')
Sleep(3000)
; delete the file
FileDelete(@TempDir & '\CMDOUT.txt')
EndFunc
Alles anzeigen