3

I want to create s subprocess in Ruby for running and interacting with other programs, and I need to use Process.spawn because Open3.popen3 does not work in Windows. Open3.popen3 gives you a nice wait-thread object that allows you to check if the process has finished via wait_thr.status, and once it was finished it allows you to get it's exit code via wait_thr.value.exitstatus.

Process.spawn only gives you the pid, so I need a way to get that data from the process id. I've looked at the Process and Kernel modules and found nothing. Process::Status has everything I need, but I can't find any information on how to create one from pid.

How can I tell when the process has finished and what was it's exit status?

Idan Arye
  • 12,402
  • 5
  • 49
  • 68

1 Answers1

1

I believe you could use the win32-api gem

You can then use the GetExitCodeProcess function from the win32 API.

Althaf Hameez
  • 1,511
  • 1
  • 10
  • 18
  • I see... well, if I need to add a requirement, I might as well find an Open3 implementation for Windows. I also tried `Process.spawn` on windows and it doesn't work... But thanks anyways! – Idan Arye Jan 14 '13 at 18:02
  • Maybe try what's given [here](http://stackoverflow.com/questions/5593616/spawning-an-independent-thread-or-process-in-ruby) – Althaf Hameez Jan 15 '13 at 02:17