July 17, 2015 at 6:03 am
H everyone,
I'm testing calling an .exe from T-Sql. Here is the code (whic his working btw:
DECLARE @sqlCmd varchar(300)
set @SqlCmd = 'powershell.exe Robocopy "C:\testSource" "c:\testDestination" *.bak /S'
EXEC xp_cmdshell @sqlCmd
Problem is though - if there is a space in the path name like say "C:\test Destination" - it throws an error like incorrect wrong parameter ie it thinks its a parameter for robocopy!
Any assistance/help here to make it work much appreciated,
J.
July 17, 2015 at 6:07 am
i think the issue is xp_cmshell;
as i remember it, with xp_cmdshell you are limited to a single pair of double quotes to a command, so ONE of your two paths can be quoted with double quotes, and the other one really has to not have spaces in it.
if this is a SQL job step, you can use a command line or run robocopy via a powershell command with dbl quotes everywhere no problem, but if you are doing it via xp_cmdshell, you need to guarantee one of your paths, either source or destination, has no spaces.
DECLARE @sqlCmd varchar(300)
set @SqlCmd = 'powershell.exe Robocopy C:\testSource "c:\test folder\ with spaces\final Destination" *.bak /S'
EXEC xp_cmdshell @sqlCmd
Lowell
July 17, 2015 at 7:20 am
Hi, thanks for that. Actually I found that this works a treat for me in my env:
set @SqlCmd = 'powershell.exe Robocopy C:\share\testSource \"c:\share\test Destination\" *.bak /S'
Cheers & thanks,
J.
July 18, 2015 at 5:00 am
curious why you're calling powershell in a cmd shell to then turn around and call robocopy. why not this?
DECLARE @sqlCmd varchar(300)
set @SqlCmd = 'Robocopy C:\testSource "c:\test folder\ with spaces\final Destination" *.bak /S'
EXEC xp_cmdshell @sqlCmd
I've seen odd return codes from robocopy so I call it from powershell to be able trap those before returning 0 to the caller but you're not showing that you use the return code.
There are no special teachers of virtue, because virtue is taught by the whole community.
--Plato
July 20, 2015 at 3:56 am
Thank you Orlando - probably ignorance on my part (to answer your question).
I'm calling this from inside a maintence plan package. I will refactor and see if it works.
Thanks for the correction etc.
J.
Viewing 5 posts - 1 through 4 (of 4 total)
You must be logged in to reply to this topic. Login to reply
This website stores cookies on your computer.
These cookies are used to improve your website experience and provide more personalized services to you, both on this website and through other media.
To find out more about the cookies we use, see our Privacy Policy