Hamid
Hamid

Reputation: 4430

Batch redirect output stderr to file and piped output stdout to file

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

I now have to port this system to windows using a batch file but I cannot seem to get access to the file twice in the one line like linux will let me, is there an alternative syntax?

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

(above is just an example)

In windows if I try to do this I get an error that the file is already being accessed. How can I make sure I get error both from the svnadmin and also from the 7za to my logfile?

Upvotes: 4

Views: 3221

Answers (2)

jeb
jeb

Reputation: 82182

You can also use a block to redirect both to the logfile directly.

Redirecting the stdout with 1>>&2 to stderr and then combine both with the parenthesis and redirect it with a single 2>> to the logfile.

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

Upvotes: 3

mousio
mousio

Reputation: 10337

This does the trick for me:

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

Upvotes: 1

Related Questions