使用 xml 参数调用 xp_cmdshell

发布于 2024-10-11 01:20:07 字数 558 浏览 3 评论 0原文

创建的控制台应用程序有两个参数:一个是像“send”这样的命令,第二个是像 "我的消息"< 这样的 xml 字符串/代码>。执行后,控制台应用程序将返回类似以下内容的内容:已处理的消息

问题是如何使用 T-SQL 调用上面提到的控制台应用程序存储过程 xp_cmdshell。主要问题是如何用xml发送参数。例如,上面提到的控制台应用程序,可以使用以下表达式执行:

"c:\consoleapp.exe" send "<Messages><msg>My message</msg></Messages>"

该表达式可以从控制台毫无问题地执行,但不能使用 xp_cmdshell。 在 xp_cmdshell 的情况下,sql server 输出将返回:

< was unexpected at this time.

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

大海や 2024-10-18 01:20:07

答案是该脚本:

EXEC master.dbo.xp_cmdshell '""D:\ConsoleTest.exe" "<Messages><msg>My message</msg></Messages>""'

The answer is that script:

EXEC master.dbo.xp_cmdshell '""D:\ConsoleTest.exe" "<Messages><msg>My message</msg></Messages>""'
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文