Closed mrbrdo closed 9 years ago
I noticed that https://github.com/jarib/childprocess also implements very similar stuff (too bad I did not find this a few days ago). And also finally found out that inheriting FDs is not possible in this case :-( Works well for Grit though.
Does jruby support the 1.9 Process::spawn
? If so, we can just fallback to that on jruby and deprecate 1.8 support.
It does support it but it does not support a lot of options. I forgot exactly which options are not supported, but basically I've looked into all stock JRuby methods in the spawn "familiy" and they each support different things, but I have not found one which supported all necessary for most "normal" tasks - setting env, in/out/err redirection (esp. err separately), chdir, and exit code. There are methods that support I think each of these but none of them support all of them in the same method.
Note (to self too): I just found it should be possible to set $? from JRuby.
JRuby.runtime.getCurrentContext.setLastExitStatus(
org.jruby.RubyProcess::RubyStatus.newProcessStatus(JRuby.runtime,
exit_code, pid))
To get PID I can maybe use more robust method than currently: org.jruby.util.ShellLauncher.getPidFromProcess(Process)
There also seem to be some things in ShellLauncher that might be used directly to get a Process with all the options set.
I'm now using more stuff from JRuby and avoided most hacks.
I think we're going to punt on JRuby support in posix-spawn. The goal of the project is to be a great process spawner in posix capable environments. I don't think JRuby support will ever reach a high enough level of quality.
JRuby's support for this is very bad, there is no single method to allow you to do everything (set env, redirect out/err/in etc). I've written a wrapper around Java ProcessBuilder to allow for this. For the moment it is enough for my needs, and is a good starting point also. Some things are a bit hacked around so that I did not need to change existing code too much (on purpose). There is one test in test_child that does not work, because I did not understand how it could work (it doesn't make sense to me). There are a substantial number of tests failing in test_spawn, mostly due to unsupported options like FD redirection (which is possible to implement but I have no time at the moment).
It's not good for merge obviously, but I hope someone will pick it up and fix the remaining specs. Also note I use platform-specific (*nix) code to figure out the PID of the spawned process and ugly hacks around $?. It is possible to avoid this but then other code must take into account that Java does not operate on PIDs.
Related #8