Re: Copy File and error code
- From: "Tibor Karaszi" <tibor_please.no.email_karaszi@xxxxxxxxxxxxxxxxxx>
- Date: Fri, 12 Jun 2009 18:33:55 +0200
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
.
- Follow-Ups:
- Re: Copy File and error code
- From: Scott
- Re: Copy File and error code
- References:
- Copy File and error code
- From: Scott
- Copy File and error code
- Prev by Date: Re: Weird Issue
- Next by Date: Re: What do people spend on self-education in the trade?
- Previous by thread: Copy File and error code
- Next by thread: Re: Copy File and error code
- Index(es):
Relevant Pages
|