简体   繁体   English

从ruby脚本调用.bat文件

[英]Invoke .bat file from ruby script

Please help me invoke a .bat file from ruby script. 请帮助我从ruby脚本调用.bat文件。 I tried the following. 我尝试了以下方法。 My test.rb file given below: 我的test.rb文件如下:

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. 不要尝试在批处理资源中使用ruby代码,它会启动cmd.exe,该脚本没有反引号或系统命令的提示。

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. 在cwd属性中转义所有\\ (或使用/资源将负责将其更改为系统分隔符)无需在没有args的单行中使用Heredoc语法,也无需在脚本中测试返回的其他行。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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