Silverlight 4 と WinForms (net4) で IronRuby コンソールを構築しています。問題なく出力をリダイレクトできます。
MyRuntime = Ruby.CreateRuntime();
msOutput = new MemoryStream();
MyRuntime.IO.SetOutput(msOutput, Encoding.UTF8);
MyEngine = MyRuntime.GetEngine("rb");
MySource = MyEngine.CreateScriptSourceFromString("a='123'\nputs a", SourceCodeKind.Statements);
MySource.Execute();
textBox2.Text = ReadFromStream(msOutput);
ここで、入力もリダイレクトしたいのですが、スクリプトから常に「nil」を取得します。
MyRuntime = Ruby.CreateRuntime();
msOutput = new MemoryStream();
msInput = new MemoryStream();
MyRuntime.IO.SetOutput(msOutput, Encoding.UTF8);
MyRuntime.IO.SetInput(msInput, Encoding.UTF8);
MyEngine = MyRuntime.GetEngine("rb");
MySource = MyEngine.CreateScriptSourceFromString("a=gets\nputs a", SourceCodeKind.Statements);
byte[] byteArray = Encoding.UTF8.GetBytes("123");
msInput.Write(byteArray, 0, byteArray.Length);
MySource.Execute();
textBox2.Text = ReadFromStream(msOutput);
入力をリダイレクトするサンプルが見つかりません。例を送っていただけますか? ありがとうございました。