简体   繁体   中英

Invoke .bat file from ruby script

Please help me invoke a .bat file from ruby script. I tried the following. My test.rb file given below:

batch "run-script" do
  cwd 'D:\\jenkins\jobs\HybrisJob\workspace'
  code <<-EOH
    `hybrisserver.bat`
  EOH
  action :run
end

but it is not working.

[2015-03-19T14:01:16+05:30] FATAL: Mixlib::ShellOut::ShellCommandFailed: batch[run-script] ((chef-apply cookbook)::(chef-apply recipe) line 1) had an error:
Mixlib::ShellOut::ShellCommandFailed: Expected process to exit with [0], but received '1'

Don't try using ruby code in a batch resource, it launch a cmd.exe, which has no clue of backticks or system command.

See the documentation here

batch "run-script" do
  cwd 'D:\\jenkins\\jobs\\HybrisJob\\workspace'
  code "hybrisserver.bat"
  action :run
end

Escape all \\ in your cwd attribute (or use / the resource will take care of changing it to system separator) There's no need to use Heredoc syntax for a single line with no args nor other lines of script testing the return.

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