Path: csiph.com!news.swapon.de!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail From: Anton Shepelev Newsgroups: comp.databases.ms-sqlserver Subject: Re: `sqlcmd' defective by design? Date: Mon, 13 May 2024 17:32:01 +0300 Organization: A noiseless patient Spider Lines: 41 Message-ID: <20240513173201.9c1a6357b3e12cfd140c12d2@g{oogle}mail.com> References: <20240513142445.206132420c1c47759b78c197@g{oogle}mail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Injection-Date: Mon, 13 May 2024 16:32:02 +0200 (CEST) Injection-Info: dont-email.me; posting-host="918042726379315a16e3ca198a19385c"; logging-data="3696848"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+Azenay+H7tldx8XRIa/8Ik9/DYKkqCJw=" Cancel-Lock: sha1:OZEHaUgyC10YlIvMWmC9gW9WE9Q= X-Newsreader: Sylpheed 3.7.0 (GTK+ 2.24.30; i686-pc-mingw32) Xref: csiph.com comp.databases.ms-sqlserver:2243 I wrote: > I have a nasty problem in my automation batch scripts that > invoke `sqlcmd`: whatever I try, I cannot cause it to > terminate with an error level in case of a timeout. The only solution I have found is to detect the words "Timeout expired" in the standard output. Here is a sample batch script: @ECHO OFF SET OUT=out.txt SET ERR=err.txt sqlcmd -S -V 11 -r -b -t 1 -i test.sql >%OUT% 2>%ERR% :: Handle a normally reported error: IF ERRORLEVEL 1 GOTO Error :: Handle a timeout, by examining the first line of stdout: SET /P OUT_FST=<%OUT% IF "%OUT_FST%"=="Timeout expired" ( ECHO equ! COPY %OUT% %ERR% GOTO :Error ) :: No errors detected, exiting: ECHO All went well. EXIT /B :Error echo Error encountered: type %ERR% I have published this on StackOverflow: -- () ascii ribbon campaign -- against html e-mail /\ www.asciiribbon.org -- against proprietary attachments