1

I am running a task from inside a batch file like this:

schtasks /run /tn TASK_NAME

The task, in turn, executes another batch file, that may exit with an error code thus:

exit -1

Is there any way to get the exit code of the task that completed?

Ovesh
  • 5,209
  • 11
  • 53
  • 73

1 Answers1

0

I think ERRORLEVEL might be what you're looking for: http://www.robvanderwoude.com/errorlevel.php

Eight-Bit Guru
  • 9,756
  • 2
  • 48
  • 62
  • That's run through the Task Scheduler Service, and not directly, so `errorlevel` is useless here. – Joey Aug 19 '10 at 15:23
  • Hmm. The question implies that the initiator of the task through Task Scheduler is a batch file, and that the task that returns -1 is a batch file. It doesn't say that the task invoked by Task Scheduler *isn't* a batch file, hence my answer assumed that it was. It would, in that case, be able to use ERRORLEVEL and pass it up to the top-level task in some way. The question asks 'how to get the exit code', and the answer is ERRORLEVEL. However, if the intent of the question was actually 'how do I pass the exit code up to the top-level initiator?' then it should probably be reworded accordingly. – Eight-Bit Guru Aug 19 '10 at 19:13