Search code examples
windowsbatch-filecommand-linestdoutread-write

Read and write to file before task is complete using cmd


Consider, I am using the command

C:\>ping www.google.com 1>a.txt 2>&1 | type a.txt

It works well as by default windows sends 4 packets, the task ends and then the file content is displayed. But when I use

C:\>ping www.google.com -t 1>a.txt 2>&1 | type a.txt

Here the task isn't complete as I have used the -t switch. How can I display the file contents as it is being written in the file. I don't want to use tee from GnuWin32 CoreUtils


Solution

  • You don't want to use tee from the GnuWin32 CoreUtils?

    Why don't you try the PowerShell version of the tee command?

    Here is a reading

    If you are insistent in using only CMD, I think it would be difficult as there is no way (AFAIK) to immediately flush the log buffer to disk.