From: Tobias Reif Date: 2003-09-03T23:49:27+09:00 Subject: Re: [windows 9*] how to get the output of commands which contain backslashes? Chris, thank you very much for the tip! It works. I appreciate any further feedback. Does the below work on "all" OSs and with most recent versions of Ruby? Mac, BSD, 1.8? To anyone else replying: please CC me. TIA :) Below is what I have now, I plan on including it in http://www.pinkjuice.com/howto/vimxml/ http://www.pinkjuice.com/howto/vimxml/setup.xml ###################################################################### # based on # www.ruby-talk.org/9739 and # www.ruby-talk.org/10006 # seems to be not necessary for Ruby 1.7.2+, see # http://www.rubygarden.org/article.php?sid=240 # please feed back improvements: # tobiasreif pinkjuice com require 'Win32API' require 'rbconfig' alias oldBackquote ` def `(command) if Config::CONFIG["arch"] =~ /win/ 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 oldBackquote command end end # test: tidy_version_command_abs = '\for-programs\use\tidy\tidy.exe -v' puts `#{tidy_version_command_abs}` tidy_version_command = 'tidy -v' puts `#{tidy_version_command}` windows_version_command = 'ver' puts `#{windows_version_command}` ruby_version_command = 'ruby -v' puts `#{ruby_version_command}` java_version_command = 'java -version' puts `#{java_version_command}` xmllint_version_command = 'xmllint --version' puts `#{xmllint_version_command}` temp_path_command = 'echo %temp%' puts `#{temp_path_command}` ###################################################################### Tobi -- http://www.pinkjuice.com/