0

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:\

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:\.

1 Answers1

1

Do the redirect inside your recipe, not when you run chef-client like:

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
Display Name is missing
  • 6,197
  • 3
  • 34
  • 46
  • I've tried this. It did not include batch script output in debug log. And the actual script would be long, so it is not convenient to redirect each command line explicitly. – David Young Jan 07 '14 at 16:00