StdoutRead()
不按换行符拆分,它只返回数据块。以下代码将数据解析为行:
Local $foo = Run(@ComSpec & " /c dir", '', 0, 2)
Local $line
Local $done = False
Local $buffer = ''
Local $lineEnd = 0
While True
If Not $done Then $buffer &= StdoutRead($foo)
$done = $done Or @error
If $done And StringLen($buffer) == 0 Then ExitLoop
$lineEnd = StringInStr($buffer, @LF)
; last line may be not LF terminated:
If $done And $lineEnd == 0 Then $lineEnd = StringLen($buffer)
If $lineEnd > 0 Then
; grab the line from the front of the buffer:
$line = StringLeft($buffer, $lineEnd)
$buffer = StringMid($buffer, $lineEnd + 1)
ConsoleWrite("START" & $line & "END" & @CRLF)
EndIf
WEnd