gpt4 book ai didi

powershell-2.0 - Chef - 从 powershell 脚本返回一个变量

转载 作者:行者123 更新时间:2023-12-04 19:07:29 33 4
gpt4 key购买 nike

我想知道是否有办法从 powershell_script 中定义的 powershell 脚本中返回变量值。资源?

我的 powershell资源如下所示:

powershell_script "Test Script" do
code <<-EOH
Write-Host "Hello World!"
return "test"
EOH
end

我想使用返回值 test从脚本中根据 if 条件在其他资源中使用。

谢谢

最佳答案

哎呀!

我认为您实际上想使用 PowershellOut Mixin found here in the Powershell cookbook .

Chef 资源很少返回值,但这就是重量级资源的用途!

如果你有 powershell 食谱,你可以这样做:

include Chef::Mixin::PowershellOut
cmd = powershell_out!('command')
cmd.stdout #=> ...
cmd.stderr #=> ...

关于powershell-2.0 - Chef - 从 powershell 脚本返回一个变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20805780/

33 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com