August 26, 2010 at 10:37 am
Hi All
I am trying to use xp_cmdshell to run a batch file but I am not having much luck.
How do I change the working directory and then call the batch file?
Thanks
Craig 🙂
August 26, 2010 at 10:46 am
why not just call the file directly? why do you have to do the cd command, when you know where the file is anyway?
create table #Results (
ID int identity(1,1) NOT NULL,
TheOutput varchar(1000))
insert into #Results (TheOutput)
exec master..xp_cmdshell 'c:\SomeFolder\MyCommandfile.bat'
select * from #Results
make sure the command you run doesn't return any prompts (do you want to delete Y/N etc) or it will hang awaiting input.
also don't forget that even if YOU can go to the command prompt and run the command, SQL uses a different set of security credentials when accessing anything outside of SQL server; make sure the account SQL runs under has access to the directory/share you are trying to access:
SQL Server uses either the account set up as the proxy account, or if that is left blank(the default) it uses account it starts with to try and access the resource:
or if the above was blank, the account in services:(or these credentials if you are sysadmin)
Lowell
Viewing 2 posts - 1 through 1 (of 1 total)
You must be logged in to reply to this topic. Login to reply