I am trying to run a shell script and capture the PID, STDERR, STDOUT and the exit status of the shell.
I am using Ruby 1.8.7, so Open3 doesn't have a way for getting the PID. I tried using the open4 gem, but unfortunately a few scripts hung while in the write process, which runs fine when manually run.
I would like to find an alternative. Your guidance will be much appreciated!
Unfortunately there isn't an easy way to do this. I tried PTY.spawn but sometimes it would fail to exec. If you can't use open3, then you can use FIFOs, but it gets a bit messy. Here's a solution I used on 1.8.7:
Nope, it's not clean. But because it uses fork and deals with the three handles itself, then you can get the PID and accomplish what open3 does.
Make sure to close your filehandles after! A yield version of this that cleans up afterwards would probably make more sense.