Groups | Search | Server Info | Login | Register
Groups > comp.databases.ms-sqlserver > #2243
| From | Anton Shepelev <anton.txt@g{oogle}mail.com> |
|---|---|
| Newsgroups | comp.databases.ms-sqlserver |
| Subject | Re: `sqlcmd' defective by design? |
| Date | 2024-05-13 17:32 +0300 |
| Organization | A noiseless patient Spider |
| Message-ID | <20240513173201.9c1a6357b3e12cfd140c12d2@g{oogle}mail.com> (permalink) |
| References | <20240513142445.206132420c1c47759b78c197@g{oogle}mail.com> |
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 <your_server> -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:
<https://stackoverflow.com/a/78472213/2862241>
--
() ascii ribbon campaign -- against html e-mail
/\ www.asciiribbon.org -- against proprietary attachments
Back to comp.databases.ms-sqlserver | Previous | Next — Previous in thread | Next in thread | Find similar
`sqlcmd' defective by design? Anton Shepelev <anton.txt@g{oogle}mail.com> - 2024-05-13 14:24 +0300
Re: `sqlcmd' defective by design? Anton Shepelev <anton.txt@g{oogle}mail.com> - 2024-05-13 17:32 +0300
Re: `sqlcmd' defective by design? Erland Sommarskog <esquel@sommarskog.se> - 2024-05-13 22:44 +0200
Re: `sqlcmd' defective by design? Anton Shepelev <anton.txt@gmail.moc> - 2024-05-14 01:05 +0300
Re: `sqlcmd' defective by design? Erland Sommarskog <esquel@sommarskog.se> - 2024-05-14 21:23 +0200
csiph-web