I was finally able to do this using Win32API and a function I call "call_and_wait".
def self;;call_and_wait(scommand_line)
cp_params = 'LPLLLLLLPP'
create_process = Win32API.new('kernel32','CreateProcess', cp_params, 'I')
startinfo = [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0].pack('LLLLLLLLLLLLSSLLLL')
# place holder for results
procinfo = [0,0,0,0].pack('LLLL')
trace("scommand_line; %s", scommand_line)
cp = create_process.call(0, scommand_line, 0, 0, 0, 0, 0, 0, startinfo, procinfo)
trace("create_process returned; %s", cp)
if (cp == 0)
return
end#if
# get process if of process we created
hProcess = procinfo.unpack("LLLL")[0]
trace("hProcess; %s waiting...", hProcess)
if (hProcess == 0)
return
end#if
waitForSingleObject = Win32API.new("kernel32","WaitForSingleObject",['L','L'],'L')
a = waitForSingleObject.Call( hProcess, 0xFFFFFFFF ) # wait forever
trace("waitForSingleObject returned; %s", a)
end#def
The WaitForSingleObject waits for the task to complete without using up resources.
The ruby command system(command_line) runs the commands and waits for it, but uses up 1/2 of the resources of the machine in a tight loop checking to see if the command is done yet.