引用Windows路径字符串

时间:2016-03-22 23:39:25

标签: ruby-on-rails ruby ruby-on-rails-3 chef chef-recipe

我在厨师中执行以下操作:

#execute
execute 'service-api install' do
  command 'c:\buildinfo\service-api\api\approot\web-#{node['default']['env']}.cmd'
end

它在Windows中运行,#{node ['默认'] [' env']}是我尝试在上面的路径字符串中引用的属性。

当我运行时,我收到以下错误:

> SyntaxError
> ==> default: -----------
> ==> default: C:\vagrant-chef\319622f1791bb50a8f9441fd4c1ff806\cookbooks\djcm_paypal_win\recipes\installService.rb:76:
> syntax error, unexpected tIDENTIFIER, expecting keyword_end
> ==> default: ...api\approot\web-#{node['default']['env']}.cmd'

如果我尝试:

 #execute
    execute 'service-api install' do
      command "c:\buildinfo\service-api\api\approot\web-#{node['default']['env']}.cmd"
    end

斜杠显示为不同的颜色(转义字符?),我收到以下错误:

[execute] The filename, directory name, or volume label syntax is incorrect.
 command "c:\buildinfo ervice-api\api\approotweb-integration.cmd"

所以它在斜线周围变得混乱,但却获得了属性。如何在带有斜杠的字符串中赋予属性?

编辑1:  我尝试了两个双斜线和另一个解决方案,即使它现在试图找到正确的路径但仍然失败,即使该文件存在于该确切的位置,我可以手动运行它。有什么想法吗?

现在的错误:

* execute[service-api install] action run
==> default:     [execute] The system cannot find the path specified.
==> default:     
==> default: 
==> default:     ================================================================================
==> default:     Error executing action `run` on resource 'execute[service-api install]'
==> default:     ================================================================================
==> default:     
==> default:     Mixlib::ShellOut::ShellCommandFailed
==> default:     ------------------------------------
==> default:     Expected process to exit with [0], but received '1'
==> default:     ---- Begin output of c:\buildinfo\service-api\api\approot\web-integration.cmd ----
==> default:     STDOUT: 
==> default:     STDERR: The system cannot find the path specified.
==> default:     ---- End output of c:\buildinfo\service-api\api\approot\web-integration.cmd ----
==> default:     Ran c:\buildinfo\service-api\api\approot\web-integration.cmd returned 1

1 个答案:

答案 0 :(得分:2)

使用单引号不允许插值。使用双引号会使反斜杠具有特殊含义,因此\b means "backspace"

您可以使用printf运算符添加内容command('c:\buildinfo\service-api\api\approot\web-%s.cmd' % node['default']['env']) - 风格:

{{1}}