Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

StreamReader Q

Status
Not open for further replies.

battleangel444

Programmer
Jun 7, 2005
1
US
Hi All

so i've got this code for a button on an asp.net page. that tries to call thecmd.exe and run a command and caputre the output. i m having a heck of a time collecting the output.

right now my code is simpley:
private void Button2_Click(object sender, System.EventArgs e)
{
StreamReader myStream;
string s_output;
myStream = System.Diagnostics.Process.Start("cmd.exe", "/c dir").StandardOutput;
s_output = myStream.ReadToEnd().Trim();
TextBox3.Text = s_output;
}
sooooo when i click the button i get an error page.

which high lights the line with "System.Diagnostics.Process.Start"
and give the description " StandardOut has not been redirected.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
"

any insight would be greatly appreciated
-Thanks
BA4^3
 
Try this

StreamReader myStream;
string s_output;

Process p = new Process();
p.StartInfo = new ProcessStartInfo("cmd.exe", "/c dir");
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.UseShellExecute = false;
p.Start();
p.WaitForExit();
myStream = p.StandardOutput;
s_output = myStream.ReadToEnd().Trim();
MessageBox.Show(s_output);
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top