IIS appcmd通过Go应用程序调用-无效的XML输入

huangapple go评论69阅读模式
英文:

IIS appcmd called via Go app - Invalid XML input

问题

我有这个命令,在直接运行命令行时可以正常工作。

import "os/exec"
...
out, err := exec.Command("cmd", "/C", `%windir%\system32\inetsrv\appcmd list APP /site.name:"My website" /text:[path='/'].physicalPath`).Output()

当我通过Go应用程序运行它时,它会抛出退出状态3222072890,并显示以下错误消息:

Failed to process input: Invalid XML input - please make sure that your XML is well-formed and follows the required format (HRESULT=c00cee3a).

我已经尝试过更改斜杠,使用不同的引号,但仍然无法正常工作。

我在Windows Server 2012 R2上使用IIS 8.5

似乎在执行之前命令就已经损坏了。有没有办法查看输出命令?

英文:

I have this command, which works when running in command line directly.

import "os/exec"
...
out, err := exec.Command("cmd", "/C", `%windir%\system32\inetsrv\appcmd list APP /site.name:"My website" /text:[path='/'].physicalPath`).Output()

When I run it via Go app, it throws <b>exit status 3222072890</b> with this error message:

Failed to process input: Invalid XML input - please make sure that your XML is well-formed and follows the required format (HRESULT=c00cee3a).

I've already tried to change slashes, use various quotation marks, but still does not work.

I use <b>IIS 8.5</b> on Windows Server 2012 R2.

It seems that command is corrupted before execution. Is there any way how to see the output command?

答案1

得分: 0

似乎是golang库中的一个错误,与Golang Github问题#15566有关。

问题是由/site.name参数中的引号引起的("My website"),这些引号被转义了,但实际上不应该转义。

这次的解决方案是:

import "os/exec"
import "syscall"
...
cmd := exec.Command(`cmd`)
cmd.SysProcAttr = &syscall.SysProcAttr{
  CmdLine: `/C %windir%\system32\inetsrv\appcmd list APP /site.name:"My website" /text:[path='/'].physicalPath`,
}
out, err := cmd.Output()

更多信息请参考:http://www.josephspurrier.com/prevent-escaping-exec-command-arguments-in-go/ 和 https://stackoverflow.com/questions/28954729/exec-with-double-quoted-argument

英文:

It seems to be a bug in golang library - related to a Golang Github issue #15566.

Issue is caused by quotation marks in /site.name argument ("My website") which are escaped, but should not be.

Solution for this time is this:

import &quot;os/exec&quot;
import &quot;syscall&quot;
...
cmd := exec.Command(`cmd`)
cmd.SysProcAttr = &amp;syscall.SysProcAttr{
  CmdLine: `/C %windir%\system32\inetsrv\appcmd list APP /site.name:&quot;My website&quot; /text:[path=&#39;/&#39;].physicalPath`,
}
out, err := cmd.Output()

For more information see: http://www.josephspurrier.com/prevent-escaping-exec-command-arguments-in-go/ and https://stackoverflow.com/questions/28954729/exec-with-double-quoted-argument

答案2

得分: 0

我刚刚删除了 XML 中的所有回车符,并移除了标签<?xml version="1.0" encoding="UTF-8"?>。而且,对于我来说,执行以下命令是有效的:

appcmd add apppool /in < C:\Installs\AppPool.xml

英文:

I just deleted all carriage returns in xml

and removed Tag
<?xml version="1.0" encoding="UTF-8"?>.

And

appcmd add apppool /in < C:\Installs\AppPool.xml

worked for me.

huangapple
  • 本文由 发表于 2017年2月19日 20:17:39
  • 转载请务必保留本文链接:https://go.coder-hub.com/42327117.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定