Re: Copy File and error code



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

.



Relevant Pages

  • Re: Copy File and error code
    ... DECLARE @ret int ... DECLARE @sMsg varchar ... DECLARE @sSource varchar ...
    (microsoft.public.sqlserver.programming)
  • Re: An open-ended maths/backgammon problem
    ... that gives a success with probability of 1/pi. ... and declare a success. ... and declare a failure. ... Only if it is the second digit in the expansion ...
    (rec.games.backgammon)
  • Re: Copy File and error code
    ... return code to get success or failure: ... DECLARE @sMsg varchar ... DECLARE @sSource varchar ... EXEC master.dbo.xp_cmdshell @sMsg ...
    (microsoft.public.sqlserver.programming)
  • Re: Copy File and error code
    ... 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? ... DECLARE @sMsg varchar ... DECLARE @sSource varchar ... EXEC master.dbo.xp_cmdshell @sMsg ...
    (microsoft.public.sqlserver.programming)
  • Re: Visual Studio Information for Borland Delphi Customers
    ... I did try to declare them, then put them down below with no success. ... recursive procedures. ... Chris Burrows ...
    (borland.public.delphi.non-technical)

Quantcast