Search code examples
chef-infrachef-recipecookbook

Cookbook to run .bat file with parameters


I have a .bat script for a deployment task. I it is needed to run with some parameters for the correct work, smthg like this:

script.bat -x=param1 -b=param2 -c=param3 ( this is how it looks in cmd on windows )

How do I correctly specify the cookbook to run a such script? I seen this done for a .sh but no .bat (yes, I need it to be a .bat not cmd or ps1) If it isn't hard, give an example. Thx


Solution

  • I would use a batch ressource like this

    batch "run-script" do
      command "script.bat -x=param1 -b=param2 -c=param3"
      cwd "Path where the script is"
      action :nothing
    end
    

    And use a notification from the deployment ressource you use

    notifies :run, "bash[run-script]", :immediately

    If the deployment ressource is correctly idempotent your script would run only if the deploy succeed.

    FWIW a .bat or a .cmd are roughtly the same thing, see Windows batch files: .bat vs .cmd?