[新手上路]批处理新手入门导读[视频教程]批处理基础视频教程[视频教程]VBS基础视频教程[批处理精品]批处理版照片整理器
[批处理精品]纯批处理备份&还原驱动[批处理精品]CMD命令50条不能说的秘密[在线下载]第三方命令行工具[在线帮助]VBScript / JScript 在线参考
返回列表 发帖
純批?CMD內置命令(不含EXE)?那恐怕很難。

不介意 PowerShell ? PowerShell 調用 FSO 應該可以。

以下是 VBS 調用 FSO 實現 TEE 例子。
在批處理中無限時地執行 Ping 命令(-t參數),不結束進程,將結果實時的輸出到螢幕和文本文件(test.txt)。

TeeExamp.cmd
  1. :: TeeExamp.cmd
  2. @echo off
  3. :: Setup
  4.   call :BuildVBS
  5.   
  6. :: Your command(s) goes here
  7.   ping -t 127.1 | %TEE% > test.txt
  8.    
  9. :: cleanup & exit
  10.   del %temp%.\T.vbs & set "TEE=" & exit /b
  11.   
  12. :BuildVBS
  13.   set TEE=cscript //nologo %temp%.\T.vbs
  14.   (echo set con = createobject("scripting.filesystemobject"^)_
  15.    echo                .opentextfile("con:", 2^)
  16.    echo do until wsh.stdin.atendofstream
  17.    echo   s = wsh.stdin.readline
  18.    echo   wsh.echo s : con.writeline FormatDateTime(Now,vbLongTime^) ^& "  " ^& s
  19.    echo loop
  20.   ) > %temp%.\T.vbs
复制代码
同步顯示:執行時,同時顯示和輸出到文件
【output .bat-file to console AND logfile.txt】
https://social.technet.microsoft ... gfiletxt?forum=ITCG

異步顯示:執行完成再顯示
【怎樣讓屏顯的結果的同時寫入到到文件中?】
http://www.bathome.net/viewthread.php?tid=23506
『千江有水千江月』千江有水,月映千江;万里无云,万里青天。    http://yu2n.qiniudn.com/

TOP

返回列表