"Phil Tomson" <ptkwt / user2.teleport.com> wrote in message
news:94vgfr$pq$1 / user2.teleport.com...
>
> I'm simply trying to run an app in a Dos window under Windows(98|NT|2K) -
> it has to run on at least all of those Windoze types -
> like:
>
> system("cmd.exe /c #{ENV[CYPRESS_DIR]}/bin/warp.exe")
>
> On NT this seems to work OK.
>
> I changed it to use command.com for Win9x:
> system("command.com /c #{ENV[CYPRESS_DIR]}/bin/warp.exe")
> -or even:
> system("command.com /c c:/warp/bin/warp.exe")
>
...
> Anyway, I thought I had all of this figured out until i started trying it
> on Win98. I discovered that there is a start command that will run the
> executable, but it runs it in a seperate window and I've found that if
> there is an error in the executable being run (like having a compiler
> compile a nonexistent file) that the other window just hangs there and
> never returns. Has anyone figured out how to get all of this to work
> consistently? I really like Ruby and I would like to use it for this
> project, but when it comes to the system and ``'s, well, they just work on
> Perl on all the WinXX platforms I've tried without any playing around...
> Can we get that kind of behaviour on Ruby eventually?
>
Hi,
To remove system command or backticks problems on Windows,
you must build ruby biniary with MS Visual C++ compiler.
or define your own method like this
require 'Win32API'
def system(command)
Win32API.new("crtdll", "system", ['P'], 'L').Call(command)
end
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
No need of "cmd.exe /c" or "command.com /c".
> Phil
Hee-Sob Park