【发布时间】:2013-09-01 07:44:16
【问题描述】:
我正在尝试从 ruby 脚本 (Ruby 1.9.3) 中运行一个名为 pdfgrep 的程序,该脚本是从 Windows 7 上的 Git Bash (MINGW32) shell 运行的。对 pdfgrep 的调用在反引号,我想得到结果并使用 ruby 方法清理它。
在查看this answer 和this answer 到a related SO question 之后,我想我应该将ENV['PATH'] 变量从Windows 样式路径转换为unix 路径,这是我的shell 中的默认路径。
(第 3 行)所以我用简单的puts 测试了$LOAD_PATH 的内容,这似乎有效。
script.rb
#!/usr/bin/env ruby
ENV['PATH'].split('\\').join(File::SEPARATOR).split(';').inject($LOAD_PATH) {|lp,v| lp << v }
# The intention is to replace puts with a variable assignment
puts `pdfgrep -i "(issued|Total)" *.pdf`
运行时我得到的错误是:
./script.rb:6:in ``': No such file or directory - pdfgrep -i "(issued|Total)" *.pdf (Errno::ENOENT)
当我提供完整路径时 - c:/Users/cjross/bin/pdfgrep -i [etc...] - 没有错误消息。它仍然没有输出我所期望的,但它不会引发错误。
基本上,我希望能够从 ruby 调用我的 shell $PATH 中的任何程序。任何建议将不胜感激。
编辑 感谢@konsolebox 纠正我不正确的引用。不幸的是仍然有路径问题。
【问题讨论】:
标签: ruby bash shell path git-bash