{"action":"closed","issue":{"url":"https://api.github.com/repos/WinRb/WinRM/issues/154","labels_url":"https://api.github.com/repos/WinRb/WinRM/issues/154/labels{/name}","comments_url":"https://api.github.com/repos/WinRb/WinRM/issues/154/comments","events_url":"https://api.github.com/repos/WinRb/WinRM/issues/154/events","html_url":"https://github.com/WinRb/WinRM/issues/154","id":113650965,"number":154,"title":"WinRM commands with no output always have 0 exit code","user":{"login":"carpnick","id":6966179,"avatar_url":"https://avatars.githubusercontent.com/u/6966179?v=3","gravatar_id":"","url":"https://api.github.com/users/carpnick","html_url":"https://github.com/carpnick","followers_url":"https://api.github.com/users/carpnick/followers","following_url":"https://api.github.com/users/carpnick/following{/other_user}","gists_url":"https://api.github.com/users/carpnick/gists{/gist_id}","starred_url":"https://api.github.com/users/carpnick/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/carpnick/subscriptions","organizations_url":"https://api.github.com/users/carpnick/orgs","repos_url":"https://api.github.com/users/carpnick/repos","events_url":"https://api.github.com/users/carpnick/events{/privacy}","received_events_url":"https://api.github.com/users/carpnick/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":20,"created_at":"2015-10-27T18:27:56Z","updated_at":"2015-10-31T18:39:49Z","closed_at":"2015-10-31T18:39:49Z","body":"If no output is returned in the winrm command, it always succeeds.\r\n\r\n While debugging issue https://github.com/chef/knife-windows/issues/311, I found that [this code](https://gist.github.com/carpnick/9c2a4b2292287172cf18)(taken partially from [winrm_session](https://github.com/chef/knife-windows/blob/master/lib/chef/knife/winrm_session.rb) always has a success  (0) exit code.  If you comment out line [16](https://gist.github.com/carpnick/9c2a4b2292287172cf18#file-winrm-failure-example-L16) and uncomment line [17](https://gist.github.com/carpnick/9c2a4b2292287172cf18#file-winrm-failure-example-L17) it exits with the appropriate exit code (100)\r\n\r\nWeird so debugging the gem:\r\n\r\n# Failure case\r\nBody Sent:\r\n```\r\n<env:Body>\r\n    <rsp:CommandLine>\r\n      <rsp:Command>&quot; exit 100&quot;</rsp:Command>\r\n    </rsp:CommandLine>\r\n  </env:Body>\r\n```\r\n\r\nReceived:\r\n```\r\n<rsp:ReceiveResponse>\r\n      <rsp:CommandState CommandId='469786EF-ACB4-47D6-AC50-087F05B78CD4' State='http://schemas.microsoft.com/wbem/wsman/1/windows/shell/CommandState/Done'>\r\n        <rsp:ExitCode>0</rsp:ExitCode>\r\n      </rsp:CommandState>\r\n    </rsp:ReceiveResponse>\r\n```\r\n\r\n\r\n# Expected/Passing use case:\r\nRequest:\r\n```\r\n<env:Body>\r\n    <rsp:CommandLine>\r\n      <rsp:Command>&quot;echo hello &amp;&amp; exit 100&quot;</rsp:Command>\r\n    </rsp:CommandLine>\r\n  </env:Body>\r\n```\r\n\r\nResponse:\r\n```\r\n<s:Body>\r\n    <rsp:ReceiveResponse>\r\n      <rsp:Stream Name='stdout' CommandId='BD6AA971-D33B-48A8-A1BC-E2B515770A89'>aGVsbG8gDQo=</rsp:Stream>\r\n      <rsp:Stream Name='stdout' CommandId='BD6AA971-D33B-48A8-A1BC-E2B515770A89' End='true'/>\r\n      <rsp:Stream Name='stderr' CommandId='BD6AA971-D33B-48A8-A1BC-E2B515770A89' End='true'/>\r\n      <rsp:CommandState CommandId='BD6AA971-D33B-48A8-A1BC-E2B515770A89' State='http://schemas.microsoft.com/wbem/wsman/1/windows/shell/CommandState/Done'>\r\n        <rsp:ExitCode>100</rsp:ExitCode>\r\n      </rsp:CommandState>\r\n    </rsp:ReceiveResponse>\r\n  </s:Body>\r\n```\r\n"}}