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?
To close an interactive command prompt, the keyboard shortcut ALT + F4 is an alternative to typing EXIT.
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.
To display the exit code for the last command you ran on the command line, use the following command: $ echo $?
Windows Command Prompt The Windows command-line interpreter uses a caret character ( ^ ) to escape reserved characters that have special meanings (in particular: & , | , ( , ) , < , > , ^ ).
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With