0

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?

dev0experiment
  • 462
  • 1
  • 7
  • 22
  • Issue seems to be caused by quotation marks in /site.name argument ("My website"). See http://www.josephspurrier.com/prevent-escaping-exec-command-arguments-in-go/ and issue on Github https://github.com/golang/go/issues/15566 – dev0experiment Feb 19 '17 at 18:14

2 Answers2

0

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

Community
  • 1
  • 1
dev0experiment
  • 462
  • 1
  • 7
  • 22
0

I just deleted all carriage returns in xml

and removed Tag .

And

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

worked for me.

  • 1
    Thank you for the answer, please provide the changes in code [block](https://meta.stackexchange.com/questions/22186/how-do-i-format-my-code-blocks) so the people could see more clearly what you have changed. Thank you – Jeremy Walters Jan 18 '19 at 15:59