开发者

How can I keep a Python script command window open when opened from a .Net application?

Now the obvious answer is to just open the script from a command line, but that isn't an option. I'm writing a simple application to syntax highlight Python and then run the scripts 开发者_如何学Cfrom the same program. A Python IDE if you will. The scripts I want to run are entirely command line programs.

I'm using a System.Diagnostics.Process object. I can either use it to run a command line prompt or to run the Python script, but the command line window will close as soon as the script errors or finishes. I need to keep it open. The ideal solution would be to open the command line and run the Python script from the command line, but I need to do it in one click from inside a .Net application.

Any ideas? Is there a better way to keep the console open?


Don't use a Windows console. Create your own console panel or window which attaches to the stdin, stdout, and stderr of the interpreter executable. Or embed your own interpreter.


I had a similar issue, I solved it by adding raw_input() at the end of the script. Even if it's not using the value the script should hold before quitting as it waits for input from the command line.

Sadly this doesn't help if the script errors out before it reaches the raw_input() line, but you'll see how far along it gets.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜