backtick calls on Windows (9*)

T

Tobias Reif

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,020
Latest member
GenesisGai

Latest Threads

Top