2013-08-18 154 views
0

我的命令:爲什麼我的CloudFormation命令失敗?

"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\'" 

誰能幫忙?

回答

1

因爲robocopy不使用標準返回碼。它實際上並不會失敗,但命令行將其返回碼解釋爲失敗。看到這個Robocopy return code reference

你需要做的是包裝robocopy並解釋返回值。

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

將其切斷,並從工作的sript粘貼,所以你需要改變的參數 - 在^ & IF東西的,但關鍵部分是在括號包裹Robocopy命令,並結束。

實際上,它將所有成功的返回代碼從robocopy轉換爲OS識別的成功代碼。

相關問題