Batch redirect stderr output to a file and output data from stdout output to a file

I have a backup script that calls an SVN dump, outputs stderr to a file, and then outputs the output to 7zip.

Now I need to transfer this system to windows using a batch file, but I can’t access the file twice on the same line, as linux will allow me, is there an alternative syntax?

svnadmin dump D:\Repo\example 2>> %logfile% | 7za a new.7z >> %logfile% 

(the above is just an example)

On Windows, if I try to do this, I get an error when the file is already available. How can I make sure that I get an error from both svnadmin and from 7za to my log file?

+4
source share
2 answers

You can also use the block to directly redirect both log files.

Redirect stdout using 1>>&2 to stderr, then combine both with a bracket and redirect it with one 2>> to the log file.

 (svnadmin dump D:\Repo\example | 7za a new.7z 1>>&2 ) 2>> %logfile% 
+3
source

This does the trick for me:

 ( svnadmin dump D:\Repo\example 2>> %logfile% | 7za a new.7z >> %logfile%.tmp ) & copy %logfile%+%logfile%.tmp 
+1
source

Source: https://habr.com/ru/post/1348092/


All Articles