From: Holden Glova Date: 2000-12-30T12:31:17+09:00 Subject: [ruby-talk:8322] open3 woes [sort of long] -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Seems as though I can't seem to take any steps forward on this problem, only sideways. Maybe someone here can give me the push in the back needed to move me forwards. Dave Thomas has recommended the use of open3 instead of using backquotes with stderr redirection enclosed within the backquotes for platform portability reasons, a wise recommendation might I add. So the previously backquoted command: `ruby -w #{file} 2>&1` Which for some reason didn't work when run through the testing framwork (this still bothers me as to why it didn't work) has changed into: streams = Open3.popen3("ruby -w #{file}") While this seems to be working so far, i have a new error (hence my mention of sideways steps). Now it seems to be appending the "file" to itself and copying the contents before it is running the command. Let me try and clarify. i pass this file (useless.rb) into the previous command: class Useless def meth puts "Useless method in a useless class" end end u = Useless.new() u.meth() I run this through another class called RuntimeInterpreter, here is it's contents: require 'open3' class RuntimeInterpreter def invoke(file) streams = Open3.popen3("ruby -w #{file}") streams.at(1).each() { |line| puts line } end end I finally test this out through the testing framework as follows: require 'runit/testcase' require 'runtimeInterpreter' class Test_RuntimeInterpreter < RUNIT::TestCase def testInvoke interpreter = RuntimeInterpreter.new() result = interpreter.invoke("../useless.rb") assert(result == "Useless method in a useless class") end end After I run my tests, it seems to have appended the entire contents of useless.rb to itself, so i end up with this after the first time I run it, each successive run appends the entire contents itself yet again. class Useless def meth puts "Useless method in a useless class" end end u = Useless.new() u.meth() class Useless def meth puts "Useless method in a useless class" end end u = Useless.new() u.meth() What the heck is going on here? I can't find any real documentation on what open3 does, aside from looking at the code which honestly doesn't make too much sense to me. From what I gather so far it should simply return me 3 separate file descriptors respectively for stdin, stdout, and stderr. Should it also copy the file contents to itself? How have i messed up? Can anyone please help me out before I commit myself to the funny farm? - -- Signed, Holden Glova -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.0.4 (GNU/Linux) Comment: For info see http://www.gnupg.org iD8DBQE6TVaHzrxa+Gy/b/4RAtjQAJ9aOB5q3xZwc5Rglbc2uMiZ5vRe7wCglzxV jnlC3R8wYw+SdNlca9HmVMM= =NK+L -----END PGP SIGNATURE-----