# MSFN Forum: How to log the results of a DOS batch file? - MSFN Forum

Page 1 of 1

## How to log the results of a DOS batch file? Rate Topic: //<![CDATA[ rating = new ipb.rating( 'topic_rate_', { url: 'http://www.msfn.org/board/index.php?app=forums&module=ajax&section=topics&do=rateTopic&t=22253&md5check=' + ipb.vars['secure_hash'], cur_rating: 0, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

### #1kukris

• Member
• Group: Members
• Posts: 111
• Joined: 28-November 03

Posted 14 July 2004 - 06:40 AM

Hi there,

I have a batch file with many commands and want the results in saved in a log file.

I tried the following:

```mybat.bat > c:\log.txt
```

The log file is there but it's empty. How can I do this?

### #2sleepnmojo

• Group: Members
• Posts: 472
• Joined: 02-March 04

Posted 14 July 2004 - 07:07 AM

It all depends on what you are doing. If your bat file only outputs error messages, you will have to grab those too. If you just want standard output messages, what you have is fine.

Check the permissions on the file. I would assume if you can create a file, you would have write access. What you have works perfectly fine.

### #3kukris

• Member
• Group: Members
• Posts: 111
• Joined: 28-November 03

Posted 14 July 2004 - 01:21 PM

I want all messages, just as they appear in the DOS-Windows. I forget to mention that I use this for a Windows 98 Custom Installation and unlike Windows 2000 / XP
the command only creates an empty file.

So is there a way to log the output to a file? Maybe a third party utility?

### #4prathapml

• Group: Patrons
• Posts: 6,791
• Joined: 14-November 03
• OS:Windows 7 x64
• Country:

Posted 17 July 2004 - 12:51 PM

To log individual 'echo' commands, here is an example (section taken from my batch file):
```ECHO Installed Programs were not registered >> %systemroot%\Temp\instTime.log
```

To log entire runs of batch files (which is what you want), use
```mybat.bat >> c:\log.txt
```

Note the double arrows, instead of single. That is needed because '>' will create/overwrite a file, but '>>' will create/add to a text file. This works in win98.

### #5kukris

• Member
• Group: Members
• Posts: 111
• Joined: 28-November 03

Posted 20 July 2004 - 03:24 PM

Thanks, I tried that, but with no luck. The log file will be created, but it is always empty. I even made a batch file that produces an error, but not even that is logged. I don't use long filenames and neither executing it from a DOS-Windows nor from Start--> run nor calling the batch file from another batch file does make a difference.

Any Ideas? Perhaps an extra DOS utility?

### #6prathapml

• Group: Patrons
• Posts: 6,791
• Joined: 14-November 03
• OS:Windows 7 x64
• Country:

Posted 22 July 2004 - 03:36 PM

kukris, on Jul 21 2004, 02:54 AM, said:

Thanks, I tried that, but with no luck. The log file will be created, but it is always empty.

That could be because you have set a
```@ECHO OFF
```
line in your batch file (the one to be logged).

### #7tgf666

• Group: Members
• Posts: 1
• Joined: 31-October 12
• OS:none specified
• Country:

Posted 31 October 2012 - 03:48 AM

i guess i wanna use something like:
test.bat > testlog.txt 2> testerrors.txt
to create 2 logs of my batch. 1 for erros, 1 for anything else
let's pretend that this is my batch called test.bat:

REM Hello
REM Are you ready to keep on being logged?
Pause
REM I thought you were!
Ekko

notice the flawed "command" on the last line for which i'd expect an entry in testerrors.txt.
however, when i use said command, i do not see the execution of the batch in my console (although it IS being executed). i can press "any key" to end the pause but i don't see _anything_ in my console window - like being in the dark.
the logs are created exactly as i expect - but i wanna still see my batch running in console so i know if i can really end the pause without looking into the txt file manually.
how can i get my 2 logs and STILL see my execution running?

This post has been edited by tgf666: 31 October 2012 - 04:01 AM

### #8jaclaz

• The Finder
• Group: Developers
• Posts: 11,436
• Joined: 23-July 04
• OS:none specified
• Country:

Posted 31 October 2012 - 03:59 AM

You need a "tee" command/app.

See:
http://www.robvander...m/unixports.php
http://www.robvander...iles/tee_nt.txt
http://www.commandline.co.uk/mtee/

jaclaz

### #9net_user

• Group: Members
• Posts: 371
• Joined: 02-June 05
• OS:Windows 7 x86
• Country:

Posted 31 October 2012 - 03:43 PM

> (will wipe out a txt file)

>> (appends a txt file)