Fwiw, I think the difficulty of exit codes in Powershell is a defect — I think a more sane behavior should be added to new versions that is disabled by default but can be enabled at shell startup. IMO, the behavior should be that the exit code of powershell.exe
should be the exit code of the last command executed. If the last executed command was:
1. "exit," the exit code should be whatever was passed to exit.
2. If the last command was a built-in language feature or cmdlet, it should return 0 for success and 1 for failure.
3. Otherwise, the last command executed a process and the exit code should be the process exit code.
And it shouldn't matter whether you executed things via –command or –file on the powershell.exe command line.
Thanks for sharing that workaround Florian.
-Adam
From: Florian Hehlen <
">
>
Reply-To: " "> " < "> > Date: Friday, July 12, 2013 9:16 AM To: " "> " < "> > Subject: [chef] RE: Re: execute a scripts included in the cookbook Ok that is sorted out:
I had to add the following:
#stop execution after first error $ErrorActionPreference="Stop"
#force all error to exit with 1 trap { write-output $_ exit 1 }
This ensures that any error will exit with 1… this is not always the case! http://stackoverflow.com/questions/15777492/why-are-my-powershell-exit-codes-always-0
Strangely adding the trap also ensured that stdout and stderr is now being shown in the chef-client output.
I have never been happier to have a script break!
Cheers, flo
From: Florian Hehlen
Hi,
Thanks for that pointer.
Is there a way to pipe the output of the script back into chef? I am running a powershell script and get a “successfully run” message although it clearly has not run
Cheers, florian
From: Ranjib Dey [
">mailto:
]
yes you can, you can use the cookbook_file to dirstribute/install the script in a location (say /usr/local/foo) and use the execute resource to invoke it (execute "/usr/local/foo"),
On Fri, Jul 12, 2013 at 6:52 AM, Florian Hehlen < " target="_blank"> > wrote: HI,
I would like to include a native script and execute it from a recipe rather than in-lining it into the recipe.
Is this possiblem
Cheers, Florian
LEGAL DISCLAIMER
LEGAL DISCLAIMER
This communication and any attached documents are strictly confidential and/or legally privileged and they may not be used or disclosed by someone who is not a named recipient. If you have received this electronic communication in error please notify the sender by replying to this electronic communication inserting the word "misdirected" as the subject and delete this communication from your system. |
Archive powered by MHonArc 2.6.16.