Question

I just experimented with a Windows batch file that executes several knife commands, and it is not working. The batch file executes the first command and then stops.

Here is the knife version:

C:\Data\SVN\dev\trunk\chef-repo> knife -v
Chef: 11.10.0

Here is the batch file, knife_cookbooks.bat:

knife cookbook upload apt
knife cookbook upload ntp
knife cookbook upload sudo
knife cookbook upload sysctl

And the output:

C:\Data\SVN\dev\trunk\chef-repo> knife_cookbooks.bat

C:\Data\SVN\dev\trunk\chef-repo> knife cookbook upload apt
Uploading apt            [2.3.8]
Uploaded 1 cookbook.

The same thing happens with other knife commands.

Has anyone gotten this to work?

Was it helpful?

Solution

Thanks @sethvargo for the tip about using "&&". Combining that with the line-continuation character "^" for readability did the trick.

I modified the batch file as follows, and it works!

knife cookbook upload apt && ^
knife cookbook upload ntp && ^
knife cookbook upload sudo && ^
knife cookbook upload sysctl

Update: I told a co-worker about this problem, and he said "Is knife a batch file? If so, use call when invoking it." So I checked, and yes indeed, knife is actually knife.bat. So I modified my batch file, and this form also works:

call knife cookbook upload apt 
call knife cookbook upload ntp 
call knife cookbook upload sudo 
call knife cookbook upload sysctl
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top