简体   繁体   English

如何在出现时将控制台输出传递给ASP.NET页面?

[英]How can I pipe console output to an ASP.NET page as it appears?

I'd like to run a console program from an ASP.NET page, pipe the output into a label or some other control, and have it updated dynamically as each Console.Writeline happens. 我想从ASP.NET页面运行一个控制台程序,将输出传输到标签或其他控件,并在每个Console.Writeline发生时动态更新。

How do I do that? 我怎么做?

You can capture standard output from another program with the ProcessStartInfo class: set RedirectStandardOutput to true, and then read the programs output from the StandardOutput property. 您可以使用ProcessStartInfo类从另一个程序捕获标准输出:将RedirectStandardOutput设置为true,然后从StandardOutput属性读取程序输出。

The data you read can be used for whatever purpose you wish. 您阅读的数据可用于您希望的任何目的。

Run the console app as a part of a web service (WCF with XML or JSON) and refresh periodically using ASP.NET AJAX . 将控制台应用程序作为Web服务(带有XML或JSON的WCF)的一部分运行,并使用ASP.NET AJAX定期刷新。 This way, data transfer is minimal, a periodic query with occasional extra data in the reply. 这样,数据传输是最小的,定期查询在回复中偶尔会有额外的数据。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM