Run Batch file from SQL

Simon Raine
Simon Raine used Ask the Experts™
on
Hi

I'm trying to run a batch file from a SQL Script but error occurs.

Script:
EXEC xp_CMDShell 'C:\Users\Simon\Desktop\Stadium\Stadium Insert\Integration Services Project7\refresh.bat'

Error:
output
'C:\Users\Simon\Desktop\Stadium\Stadium' is not recognized as an internal or external command,
operable program or batch file.
NULL
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Tom CieslikIT Engineer
Distinguished Expert 2017

Commented:
Try

"EXEC xp_CMDShell 'C:\Users\Simon\Desktop\Stadium\Stadium Insert\Integration Services Project7\refresh.bat"
since you have space in path, you must use "

or if this will not work change spaces for %20

EXEC xp_CMDShell 'C:\Users\Simon\Desktop\Stadium\Stadium%20Insert\Integration%20Services%20Project7\refresh.bat'

Author

Commented:
hi error, using %20

: output
The system cannot find the path specified.
NULL
moved bat file to folder with no spaces in name
Qlemo"Batchelor", Developer and EE Topic Advisor
Top Expert 2015
Commented:
Tom is correct about the spaces being an issue, but the correct command is
EXEC xp_CMDShell ' "C:\Users\Simon\Desktop\Stadium\Stadium Insert\Integration Services Project7\refresh.bat" '

Open in new window

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial