views:

26

answers:

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?

A: 

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

Jonners
That's run through the Task Scheduler Service, and not directly, so `errorlevel` is useless here.
Joey
correct, @Johannes. ERRORLEVEL is useless here.
Ovesh
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.
Jonners