在WinForm程序中开启Console

April 26, 2010 at 5:29 am | Posted in Uncategorized | 1 Comment

在程序中用到了IronPython,然后想到是否可以在程序中开启一个Console窗口用于调试,就像ipy.exe一样,只不过需要传入当前程序的一些变量。

用Reflector查看ipy.exe代码,复制了一个PythonConsoleHost.cs到自身代码,然后需要AllocConsole()开启Console窗口(FreeConsole关闭),因为PythonConsoleHost.Run直到Console关闭才返回,所以需要在另外一个进程中Run PythonConsoleHost。

有个小问题,关于Console.Output(Error, Input)的。因为程序中另外用到了PythonEngine,其中又调用了Console的标准输入输出,导致新开的PythonConsoleHost输出出现问题,因此需要host.Runtime.IO.SetOutput(System.Console.OpenStandardOutput(), System.Console.OutputEncoding);

1 Comment »

RSS feed for comments on this post. TrackBack URI

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s

Blog at WordPress.com. | Theme: Pool by Borja Fernandez.
Entries and comments feeds.

Follow

Get every new post delivered to your Inbox.