dongshengyin0147 2017-02-19 12:17
浏览 138
已采纳

通过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 /site.name:"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 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 /site.name 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 /site.name:"My website" /text:[path='/'].physicalPath`,
    }
    out, err := cmd.Output()
    

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

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 教务系统账号被盗号如何追溯设备
  • ¥20 delta降尺度方法,未来数据怎么降尺度
  • ¥15 c# 使用NPOI快速将datatable数据导入excel中指定sheet,要求快速高效
  • ¥15 再不同版本的系统上,TCP传输速度不一致
  • ¥15 高德地图点聚合中Marker的位置无法实时更新
  • ¥15 DIFY API Endpoint 问题。
  • ¥20 sub地址DHCP问题
  • ¥15 delta降尺度计算的一些细节,有偿
  • ¥15 Arduino红外遥控代码有问题
  • ¥15 数值计算离散正交多项式