-
-
Notifications
You must be signed in to change notification settings - Fork 942
Description
This is posted to StackOverflow as well.
I've got a little executable we'll call "decode" (written in C) that takes a block of data on stdin (an image file), converts it, and spits it back to stdout. So from the linux command line the following command works just fine:
cat image_file.format1 | ./irb/decode > image_file.format2
I'm trying to wrap this binary in some ruby code and eliminate the need for the use of regular file IO using Open3.popen3. Here's the relevant section of Ruby code:
.
.
.
Open3.popen3("decode") do |stdin, stdout, stderr, wait_thr|
stdin.write(f)
stdin.close_write
@image_data = stdout.read
@status_message = stderr.read
exit_status = wait_thr.value
end
.
.
.
Variable f contains the block of data to convert. I was writing it to file and then calling decode on the written file. When trying to run the the above code from irb using jruby, one gets the following error traceback (slightly sanitized):
Traceback (most recent call last):
16: from org/jruby/RubyKernel.java:1180:in `catch'
15: from org/jruby/RubyKernel.java:1418:in `loop'
14: from org/jruby/RubyKernel.java:1037:in `eval'
13: from t:5:in `<eval>'
12: from /home/user/dev/kf_decoder/lib/kf_decoder/kob.rb:46:in `process'
11: from org/jruby/RubyKernel.java:311:in `open'
10: from org/jruby/RubyIO.java:1179:in `open'
9: from /home/user/dev/kf_decoder/lib/kf_decoder/kob.rb:63:in `block in process'
8: from org/jruby/ext/stringio/StringIO.java:423:in `each_byte'
7: from /home/user/dev/kf_decoder/lib/kf_decoder/kob.rb:87:in `block in process'
6: from /home/user/dev/kf_decoder/lib/kf_decoder/kob.rb:205:in `decodeTiff'
5: from /home/user/dev/kf_decoder/lib/kf_decoder/tiff.rb:123:in `initialize'
4: from /home/user/.rbenv/versions/jruby-9.2.0.0/lib/ruby/stdlib/open3.rb:102:in `popen3'
3: from /home/user/.rbenv/versions/jruby-9.2.0.0/lib/ruby/stdlib/open3.rb:206:in `popen_run'
2: from org/jruby/RubyKernel.java:1642:in `spawn'
1: from org/jruby/RubyProcess.java:1570:in `spawn'
Errno::EBADF (Bad file descriptor - irb/decode
The funny thing is that the exact same code works fine unchanged in irb if I'm using the system ruby interpreter, or rubinius (both of which I have installed and can switch between using rbenv).
Can anyone tell me what gives? I'm runing ubuntu linux 18.04 LTS, and jruby 9.2.0.0 (2.5.0). Jruby is the platform of choice because of speed and other considerations, so I need to get this working.