sql server - sqlcmd not returning error -
i running following sqlcmd via power shell
$dump = sqlcmd -s $server -q $sqlcommand -t $querytimeout -b -h -1 -w
i trying write output screen
$message = "error while executing sql {0}, error details {1}" -f "$sqlcommand","$dump" write-warning $message
but $dump
empty
i not familiar sqlcmd.exe
description of expectations think sqlcmd sending information down error stream. seemingly odd common practice , therefore occurrence.
problem here variable $dump
collect information send output stream. can redirect error stream output stream redirector. more information can @ about_redirection
so using following accomplish that:
$dump = sqlcmd -s $server -q $sqlcommand -t $querytimeout -b -h -1 -w 2>&1
the linked document describes 2>&1
as
sends errors (2) , success output (1) success output stream.
now $dump
should contain looking for. careful though might contain more information expect.
Comments
Post a Comment