I’m trying to fix a JRuby bug in Vagrant http://vagrantup.com/ that
uses
ChildProcess to execute some commands. I’m wondering if anyone is
familiar
with any gotchas using ChildProcess in JRuby. Or is there a common
problem
with the way this is being done?
I’ve been able to reproduce the bug in a single file here:
That file looks complicated, but it’s actually pretty straight forward.
It
is creating two ChildProcesses (via the Subprocess class), and executing
them in order.
Vagrant::Util::Subprocess.new(“VBoxManage”, “–version”).execute
Vagrant::Util::Subprocess.new(“VBoxManage”, “–version”).execute
In the execute method, a ChildProcess is created:
process = ChildProcess.build(*@command)
stdout, stdout_writer = IO.pipe
stderr, stderr_writer = IO.pipe
process.io.stdout = stdout_writer
process.io.stderr = stderr_writer
process.duplex = true
Then it tried to read the output from the stdout pipe:
data << io.read_nonblock(READ_CHUNK_SIZE)
The first time, the ChildProcess works correctly, but the second time it
yields no output.
INFO subprocess: Starting process: [“VBoxManage”, “–version”]
DEBUG subprocess: Selecting on IO
DEBUG subprocess: stdout: 4.1.8r75467
DEBUG subprocess: Waiting for process to exit. Remaining to timeout:
32000
DEBUG subprocess: Exit status: 0
INFO subprocess: Starting process: [“VBoxManage”, “–version”]
DEBUG subprocess: Selecting on IO
DEBUG subprocess: Waiting for process to exit. Remaining to timeout:
31999
DEBUG subprocess: Exit status: 0
Any help would be greatly appreciated. Thanks!