Solved

Pipe output to a file with a batch file

Posted on 2007-12-04
4
6,352 Views
Last Modified: 2010-01-12
I am setting up a batch job that will transfer files to several machines.  How do i send the output to a file so i can tell if any machines got missed?

i would echo the machine name, then i need to send the output of if it copied or not after it.
0
Comment
Question by:Fraser_Admin
  • 2
4 Comments
 
LVL 12

Accepted Solution

by:
weareit earned 250 total points
ID: 20404199
you can use the > charactor to redirect the output to a file.

> will overwrite
>> will append

i.e.

echo Todays date is > date.txt
date >> date.txt

-saige-
0
 
LVL 4

Assisted Solution

by:gabbadar
gabbadar earned 250 total points
ID: 20404276
You can send the output of any command to file using the > or >> characters:
> - will create a new file
>> - will append to an existing file (or create if non existent)

So this would be a good start:




Echo Server1 >> c:\CopyLog.txt
xcopy \\server1\share\* \\my\destination >>c:\CopyLog.txt
Echo ---------- >> c:\CopyLog.txt
Echo Server2 >> c:\CopyLog.txt
xcopy \\server2\share\* \\my\destination >>c:\CopyLog.txt

Open in new window

0
 

Author Comment

by:Fraser_Admin
ID: 20404783
how do i send the date.  when i do date > output.txt it waits for me to press enter.  i also want to have the date/time combination?
0
 
LVL 4

Expert Comment

by:gabbadar
ID: 20405520
Rather than use the date/time program, use the variables:

echo %date% - %time%
0

Featured Post

Space-Age Communications Transitions to DevOps

ViaSat, a global provider of satellite and wireless communications, securely connects businesses, governments, and organizations to the Internet. Learn how ViaSat’s Network Solutions Engineer, drove the transition from a traditional network support to a DevOps-centric model.

Question has a verified solution.

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

I have published numerous articles here at Experts Exchange that present programs/scripts written in a language called AutoHotkey. Each of those articles has a brief paragraph describing where to download the product and how to install it. I have al…
Use this article to create a batch file to backup a Microsoft SQL Server database to a Windows folder.  The folder can be on the local hard drive or on a network share.  This batch file will query the SQL server to get the current date & time and wi…

830 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