• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 335
  • Last Modified:

How to Append both standard output and standard error of command to file in Windows 2008 R2?

I am running the batch file with dir command to find whether the file is found or not and wants to redirect the output and error to text file.Please let me know how to do this task? Thanks
0
PKTG
Asked:
PKTG
  • 2
2 Solutions
 
warbringerCommented:
dir > yourfilename.txt


I have given up my age :) as I remember old school dos.
0
 
warbringerCommented:
the actual command:

dir searchedfile.* /s >youroutputfile.txt
0
 
oBdACommented:
If you want to have both stdout and errout in the same file, you need to redirect errout to stdout, and redirect stdout as usual.
In this case:
dir >output.txt 2>&1
The "2>&1" redirects errout to stdout, and stdout is sent to output.txt.
Note that the errout redirection has to appear after the stdout redirect; this will NOT work:
dir 2>&1 >output.txt
0
 
Steve KnightIT ConsultancyCommented:
You can soon do that to multiple commands too, or the entire batch too if neede with:

@echo off
(dir whatever
echo Something else
copy this to that
) > logfile.txt 2>&1

or

batchfile.cmd >logfile.txt 2>&1

Steve
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: SQL Server Core 2016

This course will introduce you to SQL Server Core 2016, as well as teach you about SSMS, data tools, installation, server configuration, using Management Studio, and writing and executing queries.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now