SQL Server Performance Forum – Threads Archive
xp_cmdshell processHello, 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.
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.
declare @rc int
exec @rc = master..xp_cmdshell ‘copy c: ext.txt c: ext2.txt’, no_output
@rc = 0 means all went well. @rc = 1 error. Bambola.
I’m doing the following:
set @string = ‘ exec master..xp_cmdshell "copy d:mssqlhazerahazera_maslul \’ [email protected]+’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.
select @string = ‘declare @rc int exec @rc = master..xp_cmdshell "copy c: ext.txt c: ext2.txt", no_output select @rc’ Bambola.
Thank you very much!!!
You can also use declare @rc int
set @string = ‘ "copy d:mssqlhazerahazera_maslul \’ [email protected]+’maslul" ‘
exec @rc = master..xp_cmdshell @string, no_output
select @rc Cheers
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?
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? Cheers
it worked i named the file test not text