2017-02-19 12:17
浏览 68

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

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 /"My website" /text:[path='/'].physicalPath`).Output()

When I run it via Go app, it throws exit status 3222072890 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 IIS 8.5 on Windows Server 2012 R2.

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

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

2条回答 默认 最新

  • doutan2111
    doutan2111 2017-02-19 19:12

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

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

    Solution for this time is this:

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

    For more information see: and exec with double quoted argument

    点赞 评论
  • dsf6565
    dsf6565 2019-01-18 15:39

    I just deleted all carriage returns in xml

    and removed Tag .


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

    worked for me.

    点赞 评论