Sunday 3 June 2018

command line - Redirect Windows cmd stdout and stderr to a single file



I'm trying to redirect all output (stdout + stderr) of a DOS command to a single file:



C:\>dir 1> a.txt 2> a.txt
The process cannot access the file because it is being used by another process.



Is it possible, or should I just redirect to two separate files?


Answer



You want:



dir > a.txt 2>&1


The syntax 2>&1 will redirect 2 (stderr) to 1 (stdout). You can also hide messages by redirecting to NUL, more explanation and examples on MSDN.


No comments:

Post a Comment

php - file_get_contents shows unexpected output while reading a file

I want to output an inline jpg image as a base64 encoded string, however when I do this : $contents = file_get_contents($filename); print &q...