如何命令行输出重定向到使用C#一个ASPX页面? [英] How to redirect command line output to a ASPX page using c#?
问题描述
以下是我的code。使用C#来运行aspx页面的命令:
Following is my code to run a command from aspx page using c#:
string strcmd = "/k" + @"cd: C:\GWATS\bin\&&" + "waft_exe";
System.Diagnostics.Process.Start("cmd.exe", strcmd);
Response.Redirect("./result.aspx");
这是工作的罚款。但是,我想从CMD输出到我的aspx页面。谁能给我编码呢?
我工作的ASP.NET只是在过去的1周,所以我没有这样的想法。所以,请给我一个工作code这个?
This is working fine. But I want to get the output from the cmd to my aspx page. Can anyone give me coding for this? I am working on ASP.NET just for the past 1 week, hence I dont have any idea of this. So please give me a working code for this?
推荐答案
您可以从您的命令读取输出:
You can get and read the Output from your command as:
var cCommandEx = System.Diagnostics.Process.Start("cmd.exe", strcmd);
string cRetStandardOut = cCommandEx.StandardOutput.ReadToEnd();
// before the redirect wait to exit and close it
cCommandEx.WaitForExit();
cCommandEx.Close();
和使用它为您的重定向。
and use it for your redirect.
您还必须设置 RedirectStandardOutput = TRUE,
在的ProcessStartInfo()
的过程中,如果你这样做因为它不是读什么。
You must also have set RedirectStandardOutput = true,
on the ProcessStartInfo()
of your process, if you do not read anything as it is.
这篇关于如何命令行输出重定向到使用C#一个ASPX页面?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!