It was created console application that has two param: one is a command like "send" and second is a xml string like "<Messages><msg>My message</msg></Messages>"
. Console application will return something like: "<Messages><msg>Handled message</msg></Messages>"
after execution.
The question is how to call stored procedure xp_cmdshell mentioned above console application using T-SQL. The main problem is how to send parameter with xml. For example, mentioned above console application, can be executed with this expression:
"c:\consoleapp.exe" send "<Messages><msg>My message</msg></Messages>"
This expression can be executed without problem from console, but not with xp_cmdshell. In the case of xp_cmdshell sql server outut will return:
< was unexpected at this time开发者_StackOverflow社区.
The answer is that script:
EXEC master.dbo.xp_cmdshell '""D:\ConsoleTest.exe" "<Messages><msg>My message</msg></Messages>""'
精彩评论