Nathan Stults
2009-Nov-05 20:30 UTC
[Ironruby-core] Replacing StandardInput for ScriptEngine?
Hello, I am experimenting with script IO in preparation for hosting an IRB session via an embedded SSH server and/or embedded HTTP server, but I''m having trouble getting the script environment to use a custom stream for standard input. I used the following code for setting up my IronRuby environment: public Form1() { InitializeComponent(); _stdIn = new MemoryStream(); _inputWriter = new StreamWriter(_stdIn); txtStandardIn.KeyPress+=(s,e)=> { _inputWriter.Write(e.KeyChar); _inputWriter.Flush(); Debug.Write(e.KeyChar); }; _stdOut = new FifoStream(); _outputReader = new StreamReader(_stdOut); _stdOut.DataArrived += StdOutDataArrived; _scriptEngine = Ruby.CreateEngine(); _globalScope = _scriptEngine.CreateScope(); _scriptEngine.Runtime.IO.SetInput(_stdIn, Encoding.Default); _scriptEngine.Runtime.IO.SetOutput(_stdOut, Encoding.Default); } If I write "hello" + Environment.NewLine to the input stream and flush the writer and then use the ScriptEngine e to execute a "x = gets" - x is always nil. However, if I use the script engine to execute "puts ''hello''" my custom output stream is used and I see my output. I feel like I am missing a key ingredient in my setup process - any help would be appreciated. Thanks, Nathan -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://rubyforge.org/pipermail/ironruby-core/attachments/20091105/d70ff388/attachment-0001.html>
Nathan Stults
2009-Nov-05 22:40 UTC
[Ironruby-core] Replacing StandardInput for ScriptEngine?
Please disregard. The StandardInput is being set properly and IronRuby is using it. Writing to a MemoryStream (obviously) positions the stream at EOF - the next read will obviously come up empty unless the position is reset. Used a queue-based stream and all worked well. From: ironruby-core-bounces at rubyforge.org [mailto:ironruby-core-bounces at rubyforge.org] On Behalf Of Nathan Stults Sent: Thursday, November 05, 2009 12:30 PM To: ironruby-core at rubyforge.org Subject: [Ironruby-core] Replacing StandardInput for ScriptEngine? Hello, I am experimenting with script IO in preparation for hosting an IRB session via an embedded SSH server and/or embedded HTTP server, but I''m having trouble getting the script environment to use a custom stream for standard input. I used the following code for setting up my IronRuby environment: public Form1() { InitializeComponent(); _stdIn = new MemoryStream(); _inputWriter = new StreamWriter(_stdIn); txtStandardIn.KeyPress+=(s,e)=> { _inputWriter.Write(e.KeyChar); _inputWriter.Flush(); Debug.Write(e.KeyChar); }; _stdOut = new FifoStream(); _outputReader = new StreamReader(_stdOut); _stdOut.DataArrived += StdOutDataArrived; _scriptEngine = Ruby.CreateEngine(); _globalScope = _scriptEngine.CreateScope(); _scriptEngine.Runtime.IO.SetInput(_stdIn, Encoding.Default); _scriptEngine.Runtime.IO.SetOutput(_stdOut, Encoding.Default); } If I write "hello" + Environment.NewLine to the input stream and flush the writer and then use the ScriptEngine e to execute a "x = gets" - x is always nil. However, if I use the script engine to execute "puts ''hello''" my custom output stream is used and I see my output. I feel like I am missing a key ingredient in my setup process - any help would be appreciated. Thanks, Nathan -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://rubyforge.org/pipermail/ironruby-core/attachments/20091105/a5a1b81e/attachment.html>