September 23, 2010 at 7:59 pm
Hello there,
I wanted to call a batch file (which is available in network shared location) from SQL Server (T-SQL Script) using Windows Authentication mode. Below is my code:
EXEC master..xp_CMDShell '\\BO-SQL-A04\share\batch.bat'
When i try to execute the above statement i am getting output as "NULL".
When i execute the same "batch.bat" file in local hard drive. It's working file.
EXEC master..xp_CMDShell 'D:\share\batch.bat'
Could you please help me to resolve this issue?
Regards,
PT
September 23, 2010 at 11:09 pm
Any batch file executed using xp_cmdshell will have an output of NULL. However the batch file is executed and the work is done as far as xp_cmdshell is considered. xp_cmdhshell cannot be used for interactive applications (like invoking notepad.exe).
What is the batch file intended to do? Does the batch file complete the tasks it is supposed to do when run using xp_cmdshell?
Pradeep Adiga
Blog: sqldbadiaries.com
Twitter: @pradeepadiga
September 24, 2010 at 1:12 am
Hi Pradeep,
Thank you for your reply.
I have a batch file (batch.dat) which will connect to sql server and truncates a table.
If i copy the batch file into my local hard drive (c:) and if i execute it. It's working fine.
But, if i copy the same batch file into shared location (\\srtb03.dr.info.com\tb\madMMS\Nestle\batch.bat), while execution it's giving "NULL" as a result. Batch file has not been triggered (executed).
Regards,
PT
September 24, 2010 at 4:21 am
Hi Guys,
I got the answer for this issue.
We need to execute the script with domain user (WITH EXECUTE AS 'DOMAIN\USERNAME')
Also we need to grant permission to the domain user for command xp_cmdShell
GRANT EXECUTE ON sys.xp_cmdshell TO [IRIFRNT\BOIRALC]
Thanks for your assistance.
Regards,
PT
Viewing 4 posts - 1 through 3 (of 3 total)
You must be logged in to reply to this topic. Login to reply