- From: Hedge Hog <
>
- To:
- Subject: [chef] Re: Re: Accessing Knife's return values within a script (without shelling out)
- Date: Fri, 15 Apr 2011 06:39:28 +1000
- Domainkey-signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type:content-transfer-encoding; b=PbrI9j1BAzjdyx4Dft2WUugnHs8SZDh01QEy8KuuRGQSNkFUyywGi3npPf7rgaSBQ0 2oI60YyoQGHJiOfiYY1H06iIcmiPZqZ0n6KZjgeXxI0XOqUko0cvVqt2144QS73u4IO7 K4eJFANn5C4wAg/5um7owjlpZRoyd1nH+sEZo=
On Fri, Apr 15, 2011 at 12:58 AM, Daniel DeLeo
<
>
wrote:
>
On Thursday, April 14, 2011 at 5:22 AM, Hedge Hog wrote:
>
>
Hi,
>
Having got to run Knife commands from a script, without shelling out,
>
all that remains is to be able to have whichever Knife method return
>
the data from the show and list sub-commands.
>
This too does not seem to be trivial, does anyone have any pointers,
>
tips or tricks?
>
Redirecting Knife's puts output is not trivial, Knife uses STDOUT
>
throughout (tut, tut) rather than the recommended $stdout.
>
The knife run method has output as its last method rather than
>
returning the data :(
>
>
Knife is an application and not a library. The difference is that knife is
>
designed to print output to a terminal and will call Kernel#exit when it
>
encounters an error. These are not behaviors you want in a library but they
>
make knife much simpler to implement. If you want to use Chef from within a
>
ruby program, you'll have a much easier time if you study the knife commands
>
to see how to use Chef's library classes and then use those directly. That
>
will give you complete flexibility to do whatever your application requires
>
with the output, in case of error, etc.
>
That said, using knife as a library might be okay for a quick and dirty
>
hack. In Chef 0.10, almost all output from knife goes through a
>
Knife::Core::UI object, which you can access via Knife#ui. UI objects allow
>
you to assign objects to be used for stdin, stdout, and stderr.
Thanks Dan, I'll give that a try.
>
--
>
Dan DeLeo
>
>
>
Appreciate any help.
>
>
--
>
πόλλ' οἶδ ἀλώπηξ, ἀλλ' ἐχῖνος ἓν μέγα
>
[The fox knows many things, but the hedgehog knows one big thing.]
>
Archilochus, Greek poet (c. 680 BC – c. 645 BC)
>
http://wiki.hedgehogshiatus.com
>
>
--
πόλλ' οἶδ ἀλώπηξ, ἀλλ' ἐχῖνος ἓν μέγα
[The fox knows many things, but the hedgehog knows one big thing.]
Archilochus, Greek poet (c. 680 BC – c. 645 BC)
http://wiki.hedgehogshiatus.com
Archive powered by MHonArc 2.6.16.