开发者

How can I get standard out for an assembly via reflection?

开发者 https://www.devze.com 2023-03-19 21:01 出处:网络
More or less, I am dynamically executing开发者_如何学Python user code, and I would like to capture things like Write and Read methods from console, like a file or command line program would.

More or less, I am dynamically executing开发者_如何学Python user code, and I would like to capture things like Write and Read methods from console, like a file or command line program would.

Here's what my code looks like for executing a dynamic program with one Main.

  _assembly = compilerResults.CompiledAssembly;
  object o = _assembly.CreateInstance(ClassNameString);
  MethodInfo mi = _assembly.EntryPoint;
  mi.Invoke(o, null);


An assembly doesn't get a separate output. That's per process.

You'll have to listen to your own standard out or pass a stream into your generated class.


You can set the reader and writer behind Console.Out and Console.In:

Console.SetOut(new MyInterceptingTextWriter());
Console.SetIn(new MyInterceptingReader());

// your code here
0

精彩评论

暂无评论...
验证码 换一张
取 消