From: ptkwt@...1.aracnet.com (Phil Tomson) Date: 2002-01-16T03:33:35+09:00 Subject: Re: wait for Windows application to finish In article <3C442470.6030006@iastate.edu>, Mark Slagell wrote: >Mark Slagell wrote: > >> I'm having some success with the technique mentioned in ruby-talk: >> 30733, 15050, etc. for running Windows apps from Ruby scripts. But >> does anybody know of a way to vary the Win32API crtdll call so it does >> not return until the application it launched is done running? Or does >> crtdll just not support it? >> >> Mark >> >Added note: this does seem to be the default behavior in W2000 but not >in W95/98. What I'd like is to make the call wait, regardless of Windows >version. At the moment I'm trying to do this with the mingw32 1.6.6 >build, in case that matters (I suspect it doesn't). > Let me see if I understand correctly, you mean that if you redefine 'system' like: require 'Win32API' def system(command) Win32API.new("crtdll", "system", ['P'], 'L').Call(command) end that on Win2000 if you run a windows app using the redefined system that the app is launched but does not wait for that app to finish and returns to executing the next line of your script immediatly? (That's bad news!) I'm not sure how to remedy this easily from Win32API calls. I know that I was able to run on Win[95|98|NT] using my own Win32::Process (I'm reasonably sure it'll run on Win2K as well). If you want you can download it from: http://www.aracnet.com/~ptkwt/ (Win32 Extension library). You use it like: require "win32process" myProcess = Win32::Process.new("c:\\Windows\\notepad.exe","notepad tmp.txt",TRUE,Win32::CREATE_NEW_PRODUCT_GROUP,".") #check the process id: puts myProcess.pid #wait 1 second: myProcess.wait(1000) #if you want you can kill the process: myProcess.kill(exitCode) #where exitcode is an integer I've never compiled this extension with mingw, though. Phil