sketchucation logo sketchucation
    • Login
    šŸ¤‘ SketchPlus 1.3 | 44 Tools for $15 until June 20th Buy Now

    Run windows .exe and wait for completion

    Scheduled Pinned Locked Moved Developers' Forum
    3 Posts 2 Posters 522 Views 2 Watching
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • Al HartA Offline
      Al Hart
      last edited by

      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?

      Al Hart

      http:wiki.renderplus.comimageseefRender_plus_colored30x30%29.PNG
      IRender nXt from Render Plus

      1 Reply Last reply Reply Quote 0
      • P Offline
        Petruscaleus
        last edited by

        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.

        1 Reply Last reply Reply Quote 0
        • Al HartA Offline
          Al Hart
          last edited by

          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.

          Al Hart

          http:wiki.renderplus.comimageseefRender_plus_colored30x30%29.PNG
          IRender nXt from Render Plus

          1 Reply Last reply Reply Quote 0
          • 1 / 1
          • First post
            Last post
          Buy SketchPlus
          Buy SUbD
          Buy WrapR
          Buy eBook
          Buy Modelur
          Buy Vertex Tools
          Buy SketchCuisine
          Buy FormFonts

          Advertisement