Re: Copy File and error code
- From: Linchi Shea <LinchiShea@xxxxxxxxxxxxxxxxxxxxxxxxx>
- Date: Fri, 12 Jun 2009 10:25:01 -0700
Whether you set 'no_output' or not does not change the return code. In so far
as I know, you can rely on the return code to check for error.
Linchi
"Scott" wrote:
If I say "no_output' as you suggest, after running it, I get 0. Is it safe.
to assume any error will be <> 0?
"Tibor Karaszi" <tibor_please.no.email_karaszi@xxxxxxxxxxxxxxxxxx> wrote in
message news:%23e%23eWu36JHA.5932@xxxxxxxxxxxxxxxxxxxxxxx
Use the NO_OUPUT option so you don't get that message and also use the
return code to get success or failure:
DECLARE @ret int
EXEC @ret = master.dbo.xp_cmdshell @sMsg, 'no_output'
SELECT @ret --or whatever you want to do with it
--
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
http://sqlblog.com/blogs/tibor_karaszi
"Scott" <sbailey@xxxxxxxxxxxxxxx> wrote in message
news:ORpPle36JHA.4864@xxxxxxxxxxxxxxxxxxxxxxx
I'm copying a file across the network. My code works, but it returns the
below results when successful. Is there any way to modify my code to
force sql to return perhaps a simple 0 for success and maybe 1 for an
error?
CODE:
DECLARE @sMsg varchar(3000)
DECLARE @sSource varchar(1000)
DECLARE @sTarget varchar(1000)
SET @sSource = '\\Server1\C\data\myDB.MDB'
SET @sTarget = 'D:\Data\myDB.MDB'
--SET @sMsg = N'copy ' + @sSource + N' ' + @sTarget
SET @sMsg = 'copy "' + @sSource + '" "' + @sTarget + '"';
EXEC master.dbo.xp_cmdshell @sMsg
RESULTS:
1 file(s) copied
NULL
- References:
- Copy File and error code
- From: Scott
- Re: Copy File and error code
- From: Tibor Karaszi
- Re: Copy File and error code
- From: Scott
- Copy File and error code
- Prev by Date: Re: Is there a way to convert ms sql 2008 tables to XML files?
- Next by Date: Re: What do people spend on self-education in the trade?
- Previous by thread: Re: Copy File and error code
- Next by thread: Re: Copy File and error code
- Index(es):
Relevant Pages
|