[Win32utils-devel] Fwd: win32-process gem: waiting for process

Heesob Park phasis at gmail.com
Tue Sep 24 06:59:08 UTC 2013


Hi,

2013/9/24 Daniel Berger <djberg96 at gmail.com>:
>
>
> ---------- Forwarded message ----------
> From: Praful (gmail) <praful007 at gmail.com>
> Date: Mon, Sep 23, 2013 at 1:39 PM
> Subject: win32-process gem: waiting for process
> To: djberg96 at gmail.com
>
>
> Hi
>
>
>
> I was trying your win32-process gem. Sorry for the silly question but how do
> I wait for a created process to terminate after creating it? For example, if
> I have
>
>
>
>                 info = Process.Create(…)
>
>                 WaitForSingleObject(info.process_handle, 9999)
>
>                 # do some work
>
>
>
> This does not work!
>
>
>
> I'm calling a function (that wraps Process.create) several times and am
> finding the output garbled ie intermingled. I added a sleep after the call
> and this worked but would rather wait for the created process to terminate.
>
>
>
> Also, is there a way of getting the exit code of the app being executed by
> CreateProcess?
>
>
Beware the default value of close_handles option is true.

Here is a sample code:

require 'win32/process'

    info = Process.create(
      :app_name         => 'ruby -e "sleep 5;exit(3)"',
      :close_handles => false,
    )
    if(Process::Functions::WaitForSingleObject(info.process_handle,-1)==0xFFFFFFFF)
        raise SystemCallError, FFI.errno, "OpenProcess"
    end
    p Process.get_exitcode(info.process_id)



Regards,
Park Heesob


More information about the win32utils-devel mailing list