473,405 Members | 2,444 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

ERROR in xp_cmdshell syntax

6
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\folder2\folder3\'
set @filename = @path+'filename.txt'
set @new = 'newfilename.txt'
set @cmd = 'REN '+@filename+' '+@new

exec master..xp_cmdshell @cmd

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

Need technical help. please advise asap.
thnx again.
Jul 23 '07 #1
2 3751
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
Jul 23 '07 #2
This will help you. first declare the parameters and use the following code.

set @backup_filePartialname = @diff_backup_path+@db_name + '_*.bak'
set @backup_filename = @db_name + '.bak'
set @dos_cmd = 'RENAME ' + @backup_filePartialname + ' ' + @backup_filename

EXEC @dos_result = master.dbo.xp_cmdshell @dos_cmd, NO_OUTPUT
Jul 23 '07 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Yvonne | last post by:
Would like to implement Blat on SQL Server 2000. I'm looking for example syntax for setting up BLAT with xp_cmdshell. TIA
1
by: Dharmesh Gandhi | last post by:
DB-Library Error 10007: General SQL Server error: Check messages from the SQL Server. CREATE PROCEDURE . ( @srvr varchar(50),
1
by: Jagannathan Santhanam | last post by:
Hello I am trying to execute ‘xp_cmdshell' from within a DTS package that was created by another person. When I try to execute that ‘SQL Task' selectively from within the package, I get the...
1
by: Matt | last post by:
HI I am using the following code in an SP, it seems like an ugly hack I have done to check if the BCP was working or not, I check the table it shold have filled instead of checking the error...
4
by: Chris Allison | last post by:
I am getting the following error when running a command in Query Analyzer. Msg 50001, Level 1, State 50001 xpsql.cpp: Error 5 from CreateProcess on line 675 Here is the command that I am...
0
by: simon | last post by:
I have dataGrid on my page with edit button. When user click edit button and change some value and after that click update button, the following code is executed: oCmd = New...
2
by: tolcis | last post by:
Hi! I have a batch file (.bat) that I need to execute inside my stored procedure (SQL 2000). I am trying to call that batch file using xp_cmdshell command. I am probably not using it the right...
4
by: smatyk | last post by:
I have SQL statements that I run in Query Analyzer with character date values as parameters which work fine - QA recognises (for example) 20/12/2006 as dd/mm/yyyy. My QA is v 8.00.2039. But when...
1
benchpolo
by: benchpolo | last post by:
Can any tell me where to find the syntax commands for xp_cmdshell ? or a good reference book? Thanks.
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.