summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorara.t.howard <ara.t.howard@gmail.com>2010-05-20 13:17:23 -0600
committerara.t.howard <ara.t.howard@gmail.com>2010-05-20 13:17:23 -0600
commit00e5f710b425f8a4892720b93e8ea39952ebbe0c (patch)
treec59976940939e048bee2e72d03ca5baced473d43
parentb464fd82d324eb88c38bdb9c9ecf3c02ed3efdcb (diff)
parent2809f508ee2d616cb36baca19ebffd4ee87f5291 (diff)
downloadsystemu-00e5f710b425f8a4892720b93e8ea39952ebbe0c.tar.gz
Merge branch 'master' of git@github.com:ahoward/systemu
-rw-r--r--lib/systemu.rb44
1 files changed, 44 insertions, 0 deletions
diff --git a/lib/systemu.rb b/lib/systemu.rb
index bf5e829..9b4ca6a 100644
--- a/lib/systemu.rb
+++ b/lib/systemu.rb
@@ -247,6 +247,50 @@ class SystemUniversal
end
end
+# some monkeypatching for JRuby
+if defined? JRUBY_VERSION
+ require 'jruby'
+ import org.jruby.RubyProcess
+
+ class SystemUniversal
+ def systemu
+ split_argv = JRuby::PathHelper.smart_split_command @argv
+ process = java.lang.Runtime.runtime.exec split_argv.to_java(:string)
+
+ stdout, stderr = [process.input_stream, process.error_stream].map do |stream|
+ StreamReader.new(stream)
+ end
+
+ exit_code = process.wait_for
+ [
+ RubyProcess::RubyStatus.new_process_status(JRuby.runtime, exit_code),
+ stdout.join,
+ stderr.join
+ ]
+ end
+
+ class StreamReader
+ def initialize(stream)
+ @data = ""
+ @thread = Thread.new do
+ reader = java.io.BufferedReader.new java.io.InputStreamReader.new(stream)
+
+ while line = reader.read_line
+ @data << line << "\n"
+ end
+ end
+ end
+
+ def join
+ @thread.join
+ @data
+ end
+ end
+ end
+end
+
+
+
SystemU = SystemUniversal unless defined? SystemU
Systemu = SystemUniversal unless defined? Systemu