解决方法
通过传递参数,无法阻止sqlCMD返回非错误输出消息.
但是,您可以做的是将错误消息重定向到STDERR,然后将所有其他消息定向到NUL.
这是通过传递-r参数完成的.从books online开始:
-r[ 0 | 1] msgs to stderr
Redirects the error message output to the screen (stderr). If you do not specify a parameter or if you specify 0,only error messages that have a severity level of 11 or higher are redirected. If you specify 1,all error message output including PRINT is redirected. Has no effect if you use -o. By default,messages are sent to stdout.
设置-r取决于您要显示哪些错误消息,但要显示所有错误消息输出,示例命令将是:
sqlcmd -Q "select 1 as a; select 1/0 as b" -E -r1 1> NUL