SQL Server Performance

xp_cmdshell process

Discussion in 'General DBA Questions' started by marina_sirota, Sep 23, 2003.

  1. marina_sirota New Member

    Hello, friends,<br />This is probably not a question for DBA forum, but may be someone knows the answer.<br />In the stored procedure I'm using xp_cmdshell command to copy file from one dir to another.<br />How I can receive any indication what the process succeded?<br />any "return 1 or 0"?<img src='/community/emoticons/emotion-1.gif' alt=':)' />)<br />Thank you.<br />Marina Sirota.
  2. marina_sirota New Member

    I'm sorry, probably my question was not clear enough.
    xp_cmdshell return 1 or 0 if the stored procedure was invoked,
    I would like to receive an indication that the file was copied.
  3. bambola New Member

    declare @rc int
    exec @rc = master..xp_cmdshell 'copy c: ext.txt c: ext2.txt', no_output
    select @rc
    @rc = 0 means all went well. @rc = 1 error.

  4. marina_sirota New Member

    I'm doing the following:
    set @string = ' exec master..xp_cmdshell "copy d:mssqlhazerahazera_maslul \' +@local+'maslul" '

    How can I include the @rc variable into the string?
    I receive the host name into the @string, in every PC the @local will be different, so
    I really don't know how to combine those two......
    Thank you in advance.
  5. bambola New Member

    select @string = 'declare @rc int exec @rc = master..xp_cmdshell "copy c: ext.txt c: ext2.txt", no_output select @rc'

  6. marina_sirota New Member

    Thank you very much!!!
  7. Twan New Member

    You can also use

    declare @rc int
    set @string = ' "copy d:mssqlhazerahazera_maslul \' +@local+'maslul" '
    exec @rc = master..xp_cmdshell @string, no_output
    select @rc

  8. NewDBA Member

    i cannot copy the file using Bambola's statement.
    when i add exec @string it returning error otherwise it just filled the @string variable
    with that statement
    what do i do wrong?
    thank you
  9. Twan New Member

    It may be to do with blanks in filenames/directories or single quotes needing to be escaped.

    Are you able to post the code that you use?

  10. NewDBA Member

    it worked i named the file test not text

Share This Page