[英]How to redirect output of Windows batch scripts inside a Chef Coobkook into a file?
For example in this simple cookbook recipe: 例如,在这个简单的食谱中:
batch "Clear_OS_Agent" do
code <<-EOH
@echo on
dir C:\
@echo off
EOH
action :run
When I run chef-client.bat
on a Windows node, I can get the result of dir C:\\
在Windows节点上运行
chef-client.bat
时,可以获得dir C:\\
的结果。
But when I redirect in into a file chef-client.bat > C:\\chef_log.txt
, there are only the general chef-client.bat
output over there, without the result of dir C:\\
. 但是,当我重定向到一个文件
chef-client.bat > C:\\chef_log.txt
,那里只有常规的chef-client.bat
输出,而没有dir C:\\
的结果。
Do the redirect inside your recipe, not when you run chef-client like: 在您的食谱中进行重定向,而不是像下面那样运行Chef-client时:
code <<-EOH
@echo on
dir C:\ > C:\chef_log.txt
@echo off
EOH
You can probably see the results of your run how you were doing it originally if you crank up the debug as well like: 如果您启动调试,您可能会看到运行结果,如最初的样子:
chef-client.bat -l debug > C:\chef_log.txt
Edit: 编辑:
If you have multiple commands you want redirected to the same log file you can do the following so you don't have to explicitly redirect each line: 如果您有多个命令要重定向到同一个日志文件,则可以执行以下操作,因此不必显式重定向每一行:
(
echo one
echo two
echo three
dir C:\
) > C:\test.txt
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.