简体   繁体   中英

Running a windows batch command using chef blocks the chef provision

I'm using chef for windows and need to run a batch file that starts up the selenium-server java service (java -jar seleniumserver.jar) as a daemon. When I try to use a windows_batch resource, it causes chef to hang during it's provisioning.

The problem is that the selenium server stays running in whatever command line you start it in, but chef won't continue provisioning the machine until the command is finished. The thing is, the command never finishes, it's not supposed to.

Here's what I've tried so far:

  • Executing java -jar seleniumserver.jar & (with the windows_batch resource)
  • Using a template to create a batch file for the command, then using windows_batch to execute file.bat
  • Using windows_batch to execute the batchfile with an & (file.bat &)

I'm open to any ideas, even if it's kind of hacky. Thanks in advance!

If I understand the question correctly, you can start a separate process so the main batch file ends. For example:

start java -jar seleniumserver.jar

You can control several execution parameters through the different start options.

Ending command lines with & does not do the same as *nix.

async process on windows that doesn't block chef run

batch "run" do code 'powershell -c "start-process notepad.exe"' end

The following is an example of using start-process to start a command with arguments.

Try running the command by itself in the command prompt to familiarize yourself with its output.

net statistics server

Now run it using powershell and start-process in the command prompt and verify the correct output shows in c:\\output.txt. Please pay careful attention to the use of single or double quotes. My experience says start-process won't work with double quotes for some reason.

powershell -c start-process net -ArgumentList 'statistics workstation' -RedirectStandardOutput c:\output.txt

Now put the following in a Chef execute resource and run it. Again, be aware of the single quotes, double quotes and escaped single quotes.

execute "run" do
  command 'powershell -c "start-process net -ArgumentList \'statistics workstation\' -RedirectStandardOutput c:\chef-output.txt"'
end

You should find the correct output in c:\\chef-output.txt.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM