Jump to content

Logging in .cmd?

Recommended Posts

In my unattended .cmds I want to be able to log both the success and errors to one log file. With a little testing I can output success or errors but not both in one file.. How would do I output everything to one file? This is about what I have so far.. (the extent of my cmd/batch scripting knowledge :) )

:: would also like to stick the next 3 lines on one line but not important
echo Setup Log File
Date /t
Time /t
echo Copying somefile..
copy somefile.txt somefile2.txt
echo Deleting that file, just testing..
del somefile2.txt

:: should log an error but does not.. help!
echo Deleting a file that doesn't exist to test
del nosuchfile.txt
) > log.txt

Thanks for any help :yes:

Link to comment
Share on other sites

Ahh thanks Yzöwl! :D That works perfectly. Don't have to change anything but add a few characters to the end. Where is all this stuff documented anyway? I searched for a while and didn't find much info about advanced topics like this. Any good sites you know of?

John McGuire, I tried yours too but it was too much work for my lengthy script. I would have to do the if errorlevel thing for almost every command. Don't even think it outputted the error to the same file in the correct location. Still, more than I thought of. Thanks tho. ;)

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Recently Browsing   0 members

    • No registered users viewing this page.

  • Create New...