问题
@echo off
ping www.google.com > pinglog.txt
pause
I have this command but my problem is when you add ">" or ">>" the command prompt will not show what is going on on the background. Is there a way that everything will be copied after doing the ping?
I am aware of this code as well:
@echo off
ping www.google.com > pinglog.txt
type pinglog.txt
pause
but still, the screen stays blank as if nothing happens. I hope someone can help
回答1:
Pipe to a Tee command.
ping www.google.com | cscript //nologo tee.vbs - t pinglog.txt
This is from filter.bat/vbs.
Set Arg = WScript.Arguments
set WshShell = createObject("Wscript.Shell")
Set Inp = WScript.Stdin
Set Outp = Wscript.Stdout
If LCase(Arg(0)) = "tee" or LCase(Arg(0)) = "t" then Tee
Sub Tee
On Error Resume Next
Set Fso = CreateObject("Scripting.FileSystemObject")
Set File = Fso.CreateTextFile(Arg(1), True)
If err.number <> 0 then
Outp.WriteLine "Error: " & err.number & " " & err.description & " from " & err.source
err.clear
wscript.exit
End If
Do Until Inp.AtEndOfStream
Line=Inp.readline
outp.writeline Line
File.WriteLine Line
Loop
End Sub
Tee
filter tee <Filename>
filter t <Filename>
Writes Stdin to a file and StdOut
Example
filter tee "%userprofile%\Desktop\winini.txt" < "%windir%\win.ini"
来源:https://stackoverflow.com/questions/28263236/batch-file-ping-output-to-text-file