Remove this Banner Ad

Batch file help

🥰 Love BigFooty? Join now for free.

Joined
Oct 9, 2003
Posts
51,650
Reaction score
53,860
Location
Singapore / 30,000 feet
AFL Club
North Melbourne
Other Teams
Eagles (NFL), Suns (NBA)
One for the DOS savvy.
I've created a simple batch file called backup.bat that outputs the date and time before backing up my mail files from my internal HD to my external HD. This is the contents of the batch file:

Code:
time /t
date /t
cd C:\Documents and Settings\Outlook
xcopy /e/y/d/f *.* E:\Backup\Outlook
pause

When these commands are executed in the DOS console, I want to be able to capture all the text that appears in the console into a log file.
Code:
C:\>time /t
 6:38p
C:\>date /t
Sun 02/22/2009
C:\>cd C:\Documents and Settings\Outlook
C:\Documents and Settings\Outlook>xcopy /e/y/d/f *.* E:\Backup\Outlook
0 File(s) copied
C:\Documents and Settings\Outlook>pause
Press any key to continue . . .

Any help on how I can get this text above into a log file as it's being executed? Essentially, what I want to be able to do is when the batch file starts, open a log file, have everything dumped into the log file, then at the end, close the log file.
I don't just want the output of each command sent to a log file, I want both the input commands as well as the output, as they appear on the screen like the code above, sent to a log file. I've tried ECHO, COPY, TYPE, etc, but no luck.

Thanks.
 
Thanks but it's not quite what I need.

With that approach I need to open a DOS window, change directory to where the backup.bat file is located, and then type in your string.
What I want to do is double click on the batch file from my desktop and then have a command in the batch file which will send everything to a log file.
The other draw back with your approach is that nothing is outputted to the screen - everything is sent to the log file - so you don't know which command in the batch file is being executed because you don't have any visibility. All you see is the batch file start and finish but nothing in between.

Anyone else able to help with me with this? It seems like a simple problem but I haven't been able to find a solution for it yet :(
 

Log in to remove this Banner Ad

Thanks but it's not quite what I need.

With that approach I need to open a DOS window, change directory to where the backup.bat file is located, and then type in your string.
What I want to do is double click on the batch file from my desktop and then have a command in the batch file which will send everything to a log file.
The other draw back with your approach is that nothing is outputted to the screen - everything is sent to the log file - so you don't know which command in the batch file is being executed because you don't have any visibility. All you see is the batch file start and finish but nothing in between.

Anyone else able to help with me with this? It seems like a simple problem but I haven't been able to find a solution for it yet :(

Put what I said in a separate batch file and click on that. You're working with batch files which are limited in functionality. A proper language like PowerShell would be more flexible if you want to do some real work.
 
FFS, put what I said in a separate batch file and click on that.
Already tried that but there is no screen output, the called batch file (backup.bat) runs in the background so you don't know what command is being executed.
You're working with batch files. Try coding in a real language if you want to do some real work. Learn Power Shell.
I shouldn't need to code in a "real language" to do this. That's the whole point, it's a simple task that a batch file should be able to handle. I'm almost sure that I've done this before, I just can't recall how.
Trying to do this any other way would be overkill and a waste of time.
 

Remove this Banner Ad

Remove this Banner Ad

🥰 Love BigFooty? Join now for free.

Back
Top