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");
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.
You must also have set RedirectStandardOutput = true, on the ProcessStartInfo() of your process, if you do not read anything as it is.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With