Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Force exit code zero for windows command line commands

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?

like image 845
42cornflakes Avatar asked Jan 06 '15 22:01

42cornflakes


People also ask

How do you exit a script in cmd?

To close an interactive command prompt, the keyboard shortcut ALT + F4 is an alternative to typing EXIT.

What does @echo off do?

The ECHO-ON and ECHO-OFF commands are used to enable and disable the echoing, or displaying on the screen, of characters entered at the keyboard. If echoing is disabled, input will not appear on the terminal screen as it is typed. By default, echoing is enabled.

How do I find my return code using cmd?

To display the exit code for the last command you ran on the command line, use the following command: $ echo $?

How do I escape a character in cmd?

Windows Command Prompt The Windows command-line interpreter uses a caret character ( ^ ) to escape reserved characters that have special meanings (in particular: & , | , ( , ) , < , > , ^ ).


1 Answers

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

like image 177
MC ND Avatar answered Sep 30 '22 22:09

MC ND