[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

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

Posted on 2011-05-11
4
Medium Priority
?
318 Views
Last Modified: 2012-06-27
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
Comment
Question by:PKTG
  • 2
4 Comments
 
LVL 4

Expert Comment

by:warbringer
ID: 35742002
dir > yourfilename.txt


I have given up my age :) as I remember old school dos.
0
 
LVL 4

Expert Comment

by:warbringer
ID: 35742007
the actual command:

dir searchedfile.* /s >youroutputfile.txt
0
 
LVL 85

Accepted Solution

by:
oBdA earned 800 total points
ID: 35742051
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
 
LVL 43

Assisted Solution

by:Steve Knight
Steve Knight earned 200 total points
ID: 35742339
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

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

VALIDATING DATES One method of validating dates is to jam the date into the DATE command and see if it accepts it by examining the system's errorlevel value. A non-zero result indicates failure. A typical example might look something like the fol…
Being a system administrator some time we require to do things remotely, one of them is installing software. Here I am going to tell you how to install software through wmic (Windows management instrument console). I am not at all saying that this i…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
As many of you are aware about Scanpst.exe utility which is owned by Microsoft itself to repair inaccessible or damaged PST files, but the question is do you really think Scanpst.exe is capable to repair all sorts of PST related corruption issues?
Suggested Courses

834 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question