Running Childprocess twice yields no output

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!

On Jan 20, 2012, at 7:11 AM, Joe K. wrote:

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 had to patch around issues with subprocess IO lately. I wonder if
this is a regression of sorts. It could also be an issue with
childprocess too, I’ve submitted a JRuby patch to child process before.

I’ve been able to reproduce the bug in a single file here:
https://gist.github.com/1647275

So, I see the same results running with JRuby 1.6.5. It’s a bit odd that
it works the first time but not the second.

With JRuby master, I don’t see any subprocess output at all. That’s a
bit more cause for concern.

Can you file a bug for us to track this, Joe,

Thanks,
/Nick

Here it is:
http://jira.codehaus.org/browse/JRUBY-6362

I’ll dig into childprocess, too.

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs