7

How can I force the exit code to be zero for a windows cmd command without changing the way it behaves

The linux equivalent of what is mean is

netstat -an | grep 12035 || true

Something I tried is

C:\>netstat -ano | find "25000" | exit 0

Though it forces exit code 0, it does not show the desired output when successful

Eg:

C:\>netstat -ano | find "25000"
TCP    0.0.0.0:25000          0.0.0.0:0              LISTENING       4832

C:\>netstat -ano | find "25000" | exit 0

Any idea if there is a way?

1
  • The linux command works fine in its current form, if that was what you are referring to. If you are referring to the windows command, && exit 0 will just execute an exit command Commented Jan 7, 2015 at 0:11

1 Answer 1

9
netstat -an | find "25000" || ver>nul

If the find command raises errorlevel, execute a command that resets it., in this case the ver command is used and its output discarded

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

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.