0

我的命令:

"7-set-up-default" : {
        "command" : { "Fn::Join" : ["", [
                                "robocopy /move C:\\inetpub\\wwwroot\\ C:\\inetpub\\wwwroot\\Default\\\n",
                                "powershell \"Import-Module WebAdministration;",
                                             "Set-ItemProperty 'IIS:\\Sites\\Default Web Site' -name physicalpath -value 'C:\\inetpub\\wwwroot\\Default\\'\""
                            ]]},
        "waitAfterCompletion" : "0"
      },

这个不太有用的堆栈跟踪失败了:

Error encountered during build of config: Command 07-set-up-default failed
Traceback (most recent call last):
  File "cfnbootstrap\construction.pyc", line 513, in run_config
  File "cfnbootstrap\construction.pyc", line 125, in run_commands
  File "cfnbootstrap\command_tool.pyc", line 113, in apply
ToolError: Command 07-set-up-default failed
2013-08-18 08:35:29,611 [ERROR] Unhandled exception during build: Command 07-set-up-default failed
Traceback (most recent call last):
  File "cfn-init", line 122, in <module>
  File "cfnbootstrap\construction.pyc", line 117, in build
  File "cfnbootstrap\construction.pyc", line 502, in build
  File "cfnbootstrap\construction.pyc", line 513, in run_config
  File "cfnbootstrap\construction.pyc", line 125, in run_commands
  File "cfnbootstrap\command_tool.pyc", line 113, in apply
ToolError: Command 07-set-up-default failed

但是,将我的命令直接粘贴到 cmd 窗口中可以正常工作:

robocopy /move C:\inetpub\wwwroot\ C:\inetpub\wwwroot\Default\
powershell "Import-Module WebAdministration;Set-ItemProperty 'IIS:\Sites\Default Web Site' -name physicalpath -value 'C:\inetpub\wwwroot\Default\'"

任何人都可以帮忙吗?

4

1 回答 1

1

因为 robocopy 不使用标准返回码。它实际上并没有失败,但命令行将其返回代码解释为失败。请参阅此Robocopy 返回代码参考

您需要做的是包装 robocopy 并像这样解释返回值。

"a-sync" : {
  "command" : {"Fn::Join" : ["",[
  "(robocopy c:\\latest c:\\inetpub\\", {"Ref" : "Name"}, " /MIR) ^& IF %ERRORLEVEL% LEQ 4 exit /B 0"
  ]]},
  "waitAfterCompletion" : "1"
},

这是从有效的脚本中剪切和粘贴的,因此您需要更改参数 - 但关键部分是将 robocopy 命令包装在括号中,并在末尾的 ^& IF 内容中。

实际上,它将所有成功返回代码从 robocopy 转换为操作系统识别的成功代码。

于 2013-08-20T10:27:26.677 回答