Redirection of standard and error output appending to the same log file

前端 未结 4 647
孤街浪徒
孤街浪徒 2020-11-30 00:27

I need to collect the standard output and error log from several processes into one single log file.

So every output must append to this log file.

4条回答
  •  南方客
    南方客 (楼主)
    2020-11-30 00:49

    Like Unix shells, PowerShell supports > redirects with most of the variations known from Unix, including 2>&1 (though weirdly, order doesn't matter - 2>&1 > file works just like the normal > file 2>&1).

    Like most modern Unix shells, PowerShell also has a shortcut for redirecting both standard error and standard output to the same device, though unlike other redirection shortcuts that follow pretty much the Unix convention, the capture all shortcut uses a new sigil and is written like so: *>.

    So your implementation might be:

    & myjob.bat *>> $logfile
    

提交回复
热议问题