I'm trying to run a program called pdfgrep
from within a ruby script (Ruby 1.9.3), which is run from a Git Bash (MINGW32) shell on Windows 7. The call to pdfgrep
is within backticks, I would like to get the result and clean it up using ruby methods.
After viewing this answer and this answer to a related SO question , I figured I should convert the ENV['PATH']
variable to unix paths from the Windows style paths that is the default in my shell.
(Line 3) So I have tested the contents of $LOAD_PATH
with a simple puts
, and that seems to be working.
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`
The error I get when running this is:
./script.rb:6:in ``': No such file or directory - pdfgrep -i "(issued|Total)" *.pdf (Errno::ENOENT)
When I supply the full path - c:/Users/cjross/bin/pdfgrep -i [etc...]
- there is no error message. It still doesn't output what I expect but it doesn't raise an error.
Basically I would love to be able to call any program in my shell's $PATH
from ruby. Any advice would be appreciated.
EDIT Thank you @konsolebox for correcting my incorrect quoting. Still have the path issue unfortunately.
puts `pdfgrep -i '(issued|Total)' "*.pdf"`
我认为应该像
puts `pdfgrep -i "(issued|Total)" *.pdf`
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.