I have written a Vim plugin which shells out to run external commands. Two of the commands I run are diff
and grep
which can each exit with a non-zero exit code during "normal" operation.
( diff
exits with exit code 1 when it finds differences and grep
exits with exit code 1 when it doesn't find matches.)
For the purposes of my Vimscript I need to return an exit code of 0 from these commands. So far I'm constructing the commands like this:
diff a b || true
And:
grep foo bar || true
This works for me on OS X and it apparently works for some Windows users. However, when I run Windows 7 on OS X via VirtualBox, using the Bash installed by the Git installer, I get the error message:
'true' is not recognized as an internal or external command, operable program or batch file.
What is the correct successful-no-op command to use on Windows?
true
大致相当于(exit 0)
(括号创建一个以状态0退出的子shell,而不是退出当前shell。
VER>NUL
works for me.
For example,
MKDIR . || VER>NUL
issues an error message, but it sets %ERRORLEVEL%
to 0.
The context is a Windows cmd
shell (used by the git-cmd.bat
script ):
Following " Exiting batch with EXIT /BX
where X>=1
acts as if command completed successfully when using &&
or ||
operators between batch calls ", you could define in your path a true.bat
file with:
@%COMSPEC% /C exit 1 >nul
cd .
also sets %ERRORLEVEL%
to 0 but runs a bit faster and writes a bit shorter than ver>nul
. Example:
mkdir . 2>nul || cd .
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.