From: MENON Jean-Francois Date: 2002-06-02T13:15:15+09:00 Subject: Re: "system" and Windows "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) > end > > # code 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: 1) it takes only one argument 2) it always set "$?" variable to false -- _________________________________________ / do you play Go? \ |http://jeanfrancois.menon.free.fr/rubygo | \ / ----------------------------------------- \ ^__^ \ (oo)\_______ (__)\ )\/\ ||----w | || ||