简体   繁体   English

批量重定向输出stderr到文件和管道输出stdout到文件

[英]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. 我有一个调用SVN转储的备份脚本,将stderr输出到文件然后将输出通过管道传输到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? 我现在必须使用批处理文件将此系统移植到Windows,但我似乎无法在一行中访问该文件两次,就像linux会让我,是否有替代语法?

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. 在Windows中如果我尝试这样做,我得到一个错误,该文件已被访问。 How can I make sure I get error both from the svnadmin and also from the 7za to my logfile? 我怎样才能确保从svnadmin以及从7za到我的日志文件都出错?

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. 将带有1>>&2的stdout重定向到stderr,然后将它们与括号结合,并将其与单个2>>重定向到日志文件。

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

这对我有用:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM