Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting process status and exit code from process id in ruby

Tags:

process

ruby

pid

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?

like image 656
Idan Arye Avatar asked Dec 07 '25 10:12

Idan Arye


1 Answers

I believe you could use the win32-api gem

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

like image 74
Althaf Hameez Avatar answered Dec 09 '25 00:12

Althaf Hameez