純批?CMD內置命令(不含EXE)?那恐怕很難。
不介意 PowerShell ? PowerShell 調用 FSO 應該可以。
以下是 VBS 調用 FSO 實現 TEE 例子。
在批處理中無限時地執行 Ping 命令(-t參數),不結束進程,將結果實時的輸出到螢幕和文本文件(test.txt)。
TeeExamp.cmd- :: TeeExamp.cmd
- @echo off
- :: Setup
- call :BuildVBS
-
- :: Your command(s) goes here
- ping -t 127.1 | %TEE% > test.txt
-
- :: cleanup & exit
- del %temp%.\T.vbs & set "TEE=" & exit /b
-
- :BuildVBS
- set TEE=cscript //nologo %temp%.\T.vbs
- (echo set con = createobject("scripting.filesystemobject"^)_
- echo .opentextfile("con:", 2^)
- echo do until wsh.stdin.atendofstream
- echo s = wsh.stdin.readline
- echo wsh.echo s : con.writeline FormatDateTime(Now,vbLongTime^) ^& " " ^& s
- echo loop
- ) > %temp%.\T.vbs
复制代码
|