ERROR in xp_cmdshell syntax

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • ssshhh
    New Member
    • Jun 2007
    • 6

    ERROR in xp_cmdshell syntax

    hi!
    I'm usng SQL server and i want to rename a file using the xp_cmdshell.

    here's my code:

    declare @path varchar (20)
    declare @filename varchar (20)
    declare @new varchar (20)
    declare @cmd varchar (20)

    set @path = 'E:\folder1\fol der2\folder3\'
    set @filename = @path+'filename .txt'
    set @new = 'newfilename.tx t'
    set @cmd = 'REN '+@filename+' '+@new

    exec master..xp_cmds hell @cmd

    ---
    after running, i get this error:
    The syntax of the command is incorrect.

    Need technical help. please advise asap.
    thnx again.
  • voroojak
    New Member
    • Feb 2007
    • 92

    #2
    hi
    i am not sure but i think u have to delclare another variable such as @result and then
    execute @result=master. .xp_cmdshell @cmd
    i hope it work

    Comment

    • bharadwaj
      New Member
      • Jun 2007
      • 22

      #3
      This will help you. first declare the parameters and use the following code.

      set @backup_filePar tialname = @diff_backup_pa th+@db_name + '_*.bak'
      set @backup_filenam e = @db_name + '.bak'
      set @dos_cmd = 'RENAME ' + @backup_filePar tialname + ' ' + @backup_filenam e

      EXEC @dos_result = master.dbo.xp_c mdshell @dos_cmd, NO_OUTPUT

      Comment

      Working...