同时捕获和显示 STDOUT [英] Capture and display STDOUT at the same time
本文介绍了同时捕获和显示 STDOUT的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有以下代码来捕获和处理运行命令输出.如何修改它以便运行命令窗口显示输出并同时记录输出?用 @SW_SHOW
(或等价物)替换 @SW_HIDE
只会显示一个空白的命令窗口.
I have the following code to capture and process the Run command output.
How do I modify it such that the Run command window displays output and at the same time the output gets logged? Replacing @SW_HIDE
with @SW_SHOW
(or the equivalent) just shows a blank command window.
类似于 linux tee
命令,它在打印 STDOUT 时记录到文件.
Something similar to the linux tee
command which logs to file while it prints STDOUT.
$CurrentPID = Run(@ComSpec & ' /c ' & $CurrentLogCmd, "", @SW_HIDE, $STDERR_CHILD + $STDOUT_CHILD)
If Not ProcessWaitClose($CurrentPID,60) Then
WriteLog("[Warning] Timed-out.Finding date in current hour raw log -" & $CurrentLogFileName)
$F_LogWarningExist = 1
Return $C_SUCCESS ; Take chances and proceed with parsing raw logs
EndIf
$CurrentOutput = StdoutRead($CurrentPID)
推荐答案
ConsoleWrite(_getDOSOutput('ipconfig /all') & @CRLF)
Func _getDOSOutput($command)
Local $text = '', $Pid = Run('"' & @ComSpec & '" /c ' & $command, '', @SW_HIDE, 2 + 4)
While 1
$text &= StdoutRead($Pid, False, False)
If @error Then ExitLoop
Sleep(10)
WEnd
Return StringStripWS($text, 7)
EndFunc ;==>_getDOSOutput
也许这对你有帮助.
这篇关于同时捕获和显示 STDOUT的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文