开发者

call xp_cmdshell with xml parameter

开发者 https://www.devze.com 2023-02-04 13:47 出处:网络
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 app

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>""'
0

精彩评论

暂无评论...
验证码 换一张
取 消