From: Tobias Reif Date: 2003-09-05T00:25:21+09:00 Subject: backtick calls on Windows (9*) Hi I'm disappointed to see that stuff like www.ruby-talk.org/9739 and www.ruby-talk.org/10006 still is required with the latest version of Ruby on Windows. Over the years there have been many long threads already, so in order to not increase the list volume too much, this is a one-post wish for (one aspect of) better Windows support. (Not a fifty-message thread about how lame Windows is :) Here's an illustration of the problem: (Ruby hackers (implementers) please feel free to contact me offlist for further details if required) # latest PragProg installer # ruby 1.8.0 (2003-08-04) [i386-mswin32] tidy_version_command = 'tidy -v' puts `#{tidy_version_command}` # backticks:6:in ``': No such file or directory - # tidy -v (Errno::ENOENT) xmllint_version_command = 'xmllint --version' puts `#{xmllint_version_command}` # backticks:11:in ``': No such file or directory # - xmllint --version (Errno::ENOENT) $:<<'[/path/to]/ruby/shared/' # path string changed in post require 'cross_os_calls.rb' tidy_version_command = 'tidy -v' puts `#{tidy_version_command}` # HTML Tidy for Windows released on 1st February 2003 xmllint_version_command = 'xmllint --version' puts `#{xmllint_version_command}` #[...]\XMLLINT.EXE: using libxml version 20510 [...] ... where cross_os_calls.rb goes something like this: require 'rbconfig' alias oldBacktick ` def `(command) if Config::CONFIG["arch"] =~ /win/ require 'Win32API' popen = Win32API.new("crtdll", "_popen", ['P','P'], 'L') pclose = Win32API.new("crtdll", "_pclose", ['L'], 'L') fread = Win32API.new("crtdll", "fread", ['P','L','L','L'], 'L') feof = Win32API.new("crtdll", "feof", ['L'], 'L') saved_stdout = $stdout.clone psBuffer = " " * 128 rBuffer = "" f = popen.Call(command,"r") while feof.Call( f )==0 l = fread.Call( psBuffer,1,128,f ) rBuffer += psBuffer[0..l] end pclose.Call f $stdout.reopen(saved_stdout) rBuffer else oldBacktick command end end It might be a good idea to include something like the above in Ruby. Tobi -- http://www.pinkjuice.com/