Re: Copy File and error code
- From: "Scott" <sbailey@xxxxxxxxxxxxxxx>
- Date: Fri, 12 Jun 2009 11:51:50 -0500
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@xxxxxxxxxxxxxxxxxxxxxxxI'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: John Bell
- Re: Copy File and error code
- From: Linchi Shea
- Re: Copy File and error code
- References:
- Copy File and error code
- From: Scott
- Re: Copy File and error code
- From: Tibor Karaszi
- Copy File and error code
- Prev by Date: Re: What do people spend on self-education in the trade?
- Next by Date: Re: How to automatically insert new records into Child Table using Tri
- Previous by thread: Re: Copy File and error code
- Next by thread: Re: Copy File and error code
- Index(es):
Relevant Pages
|