2

When I schedule a task to execute using the Windows 2008 Task Scheduler, it always executes behind the scenes and I am unable to see the output of it. Generally I execute a bunch of .bat files and I'm used to seeing the cmd window pop up when the scheduler kicks it off. This makes debugging much easier.

I tried redirecting the output to a file, but I found only the output of the .bat file there, not of the program that the .bat file kicked off, which is by far the more interesting output.

I would prefer being able to see the cmd window as it executes, but if I could solve this problem by getting the subject program output to a log file, I would still be delighted.

3 Answers 3

5

you have two options for running this task one is if somebodies logged in and one is run whether somebodys logged in or not. I'd just switch the task to must be logged in for debugging then switch it back to the later for normal use.

1
  • This was very helpful, although you didn't mention the key aspect of doing this, which is that the cmd window shows up if the user is required to be logged in.
    – ep4169
    Jul 13, 2010 at 16:37
3

It sounds like you want to redirect the output of the command called from within the .bat file.

Example.bat

dir \ > Example_output.txt 2>&1

In this case, Example.bat runs a "dir" command on the "\" root directory, and the ">" sends the output of that dir to the file Example_output.txt. The 2>&1 modifies the redirection to include both STDOUT and STDERR, so you'll get everything in your logfile.

Also, the ">" redirection overwrites the output file each time. Use ">>" to append to the existing file, if you want a running log over time.

1
  • This was also a helpful tip; sorry I can't upvote you--not enough rep.
    – ep4169
    Jul 13, 2010 at 16:40
0

It's possible that it redirected the output AND the commands, if you didn't start your batch file with the line

@echo off

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .