Run windows .exe and wait for completion
-
For the RpTreeMaker app I want to run a Windows .exe, passing it an argument, and wait for the execution to complete.
We have been using system(command_line) for this, but as SketchUp waits, it uses up too many machine cycles.
I tried Win32API and ShellExecute, but it doesn't wait.
I tried UI.openURL(sexec), but couldn't see to get it to work with arguments.
Does anyone have any other ideas?
-
Well, I doubt this will be any help to you, but in simple batch file I would use the START command along with the parameter /WAIT
start /wait yourprogram.exe <parameters you want to pass along> next_command (will be executed when yourprogram.exe has terminated)...but perhaps you can use it somehow.
-
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#defThe 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.
Hello! It looks like you're interested in this conversation, but you don't have an account yet.
Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.
With your input, this post could be even better 💗
Register LoginAdvertisement