1

How can I get the return status of a command ran, while outputting any messages to out-null.

Right now I have

{command} | out-null

I would like to get the return status $? of that command though. Anyway to do that?

Thanks

4
  • Is the command native or an external application? Commented Oct 8, 2013 at 15:29
  • @nimizen external, its schtasks Commented Oct 8, 2013 at 15:31
  • I'm guessing $LastExitCode will still hold the exit code, can you check? As a rule of thumb use $? for CMDLets and $LastExitCode for external apps. Commented Oct 8, 2013 at 15:41
  • @nimizen Yeah, that works. Thanks! Add that as an answer please. Commented Oct 8, 2013 at 15:54

2 Answers 2

1

As requested, here's my comment as an answer... I'm guessing $LastExitCode will still hold the exit code; as a rule of thumb use $? for CMDLets and $LastExitCode for external apps.

Sign up to request clarification or add additional context in comments.

Comments

0

exit $LastExitCode

You will get above return code on windows CLI using echo %errorlevel%. You can also return custom error code like this - exit 84

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.