“Morris, Chris” wrote:
I have cut & paste the code in my program and it doesn’t work :-<
(in fact now, no command work :-<)Here it is again copied from the very file I use. Maybe the web rendition
messed up some of the characters (I know it doesn’t render backslashes
correctly for me):code by Hee-Sob Park - posted here:
http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-talk/10006
def system(command)
Win32API.new(“crtdll”, “system”, [‘P’], ‘L’).Call(command)
endcode by Hee-Sob Park - posted here:
http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-talk/10006
def `(command)
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
end
thank you, “system” works very well now.
But I see two potential problems that make not consistent with the
original ruby command:
- it takes only one argument
- it always set “$?” variable to false
···
–
/ do you play Go? \
\ ^__^
\ (oo)\_______
(__)\ )\/\
>>----w |
>> >>