How to parse out ShellOut


#1

Hi All,

I am working on a use case where I am looking a way to parse out ShellOut
and issue a reboot if the condition is met? I’ve highlighted what I need
to look for to issue a reboot.

Mixlib::ShellOut::ShellCommandFailed

Expected process to exit with [0], but received ‘1’
---- Begin output of “powershell.exe” -NoLogo -NonInteractive -NoProfile
-ExecutionPolicy RemoteSigned -InputFormat None -File
"C:/Users/ADMINI~1/AppData/Local/Temp/2/chef-script20150213-808-kkqdzx.ps1"
----STDOUT:
STDERR: Please restart the computer before trying to install more
roles/features
---- End output of “powershell.exe” -NoLogo -NonInteractive -NoProfile
-Executio

Thanks & Regards,
Sachin Gupta


#2

Sachin,

You can check and see if shell_out returned an error using the '.error?'
method. As an example:

command = shell_out(“command to be run”)
if command.error?

do something to handle the error

else

do something else

end

How you integrate this with your recipe/cookbook will depend a little more
on the specifics of your use-case.

HTH,

Brandon Raabe

On Sat, Feb 14, 2015 at 6:42 AM, Sachin Gupta guptasachin1112mrt@gmail.com
wrote:

Hi All,

I am working on a use case where I am looking a way to parse out ShellOut
and issue a reboot if the condition is met? I’ve highlighted what I need
to look for to issue a reboot.

Mixlib::ShellOut::ShellCommandFailed

Expected process to exit with [0], but received ‘1’
---- Begin output of “powershell.exe” -NoLogo -NonInteractive -NoProfile
-ExecutionPolicy RemoteSigned -InputFormat None -File
"C:/Users/ADMINI~1/AppData/Local/Temp/2/chef-script20150213-808-kkqdzx.ps1"
----STDOUT:
STDERR: Please restart the computer before trying to install more
roles/features
---- End output of “powershell.exe” -NoLogo -NonInteractive -NoProfile
-Executio

Thanks & Regards,
Sachin Gupta


#3

Thanks Brandon,

It really helps…

Thanks!!
Sachin

On Sun, Feb 15, 2015 at 1:33 AM, Brandon Raabe brandocorp@gmail.com wrote:

Sachin,

You can check and see if shell_out returned an error using the '.error?'
method. As an example:

command = shell_out(“command to be run”)
if command.error?

do something to handle the error

else

do something else

end

How you integrate this with your recipe/cookbook will depend a little more
on the specifics of your use-case.

HTH,

Brandon Raabe

On Sat, Feb 14, 2015 at 6:42 AM, Sachin Gupta <
guptasachin1112mrt@gmail.com> wrote:

Hi All,

I am working on a use case where I am looking a way to parse out
ShellOut and issue a reboot if the condition is met? I’ve highlighted what
I need to look for to issue a reboot.

Mixlib::ShellOut::ShellCommandFailed

Expected process to exit with [0], but received ‘1’
---- Begin output of “powershell.exe” -NoLogo -NonInteractive -NoProfile
-ExecutionPolicy RemoteSigned -InputFormat None -File
"C:/Users/ADMINI~1/AppData/Local/Temp/2/chef-script20150213-808-kkqdzx.ps1"
----STDOUT:
STDERR: Please restart the computer before trying to install more
roles/features
---- End output of “powershell.exe” -NoLogo -NonInteractive -NoProfile
-Executio

Thanks & Regards,
Sachin Gupta


#4

Did you try using the reboot_pending? dsl method? I’d be curious to know
that if it detects this situation.

execute “install more software” do
command "powershell some things"
not_if { reboot_pending? }
end