RedirectStandardError + "has encountered a problem and needs toclose"

  • Thread starter Thread starter sbobek
  • Start date Start date
S

sbobek

Within an intranet ASP.Net application (framework 2.0) I make a call
to a .Net console application.

The console application writes out several messages by Console.Write
and it might throw exceptions that both the messages and the
exceptions I intend to get into my ASP.Net application.

The code snippet is part of a method that runs in a separate thread.

[...]
Process p = new Process();
p.StartInfo.FileName = consoleApplication;
p.StartInfo.Arguments = parameters;
p.StartInfo.CreateNoWindow = true;
p.StartInfo.UseShellExecute = false;
p.StartInfo.RedirectStandardError = true;
p.StartInfo.RedirectStandardOutput = true;
p.Start();
p.WaitForExit();
string error = p.StandardError.ReadToEnd();
string output = p.StandardOutput.ReadToEnd();
[...]

In either case - the console application throws an exception or it
does not - the variables "error" and "output" are filled correctly.

The problem is that in case the console application throws an
exception Windows pops up a message that the console application "has
encountered a problem and needs to close". As it runs on a web server,
that is a very unfavourable situation.

I should say by using "Process.StartInfo.RedirectStandardError = true"
the Windows popup was disabled. Sadly, it is not.

Therefore I'm looking for a solution to suppress the Windows popup.

Instead of a windows setting I'd appreciate a programmable solution or
at least a new suggestion as how to call a console application out of
another application and catching its exceptions or read the
exception's text without getting that troublesome popup.

Thanks in advance!
 
Ravi,

thanks for your reply. Unfortunately, that doesn't help.

Since the console application is implemented by myself I solved the problem
by doing all the code of the console application's Main-method into a single
try-block that catches exceptions and writes them out by "Console.Write".

Steffen


Ravi Bhavnani said:
Would it help to also set ProcessStartInfo.ErrorDialog to false?

/ravi

---------------------
Within an intranet ASP.Net application (framework 2.0) I make a call
to a .Net console application.

The console application writes out several messages by Console.Write
and it might throw exceptions that both the messages and the
exceptions I intend to get into my ASP.Net application.

The code snippet is part of a method that runs in a separate thread.

[...]
Process p = new Process();
p.StartInfo.FileName = consoleApplication;
p.StartInfo.Arguments = parameters;
p.StartInfo.CreateNoWindow = true;
p.StartInfo.UseShellExecute = false;
p.StartInfo.RedirectStandardError = true;
p.StartInfo.RedirectStandardOutput = true;
p.Start();
p.WaitForExit();
string error = p.StandardError.ReadToEnd();
string output = p.StandardOutput.ReadToEnd();
[...]

In either case - the console application throws an exception or it
does not - the variables "error" and "output" are filled correctly.

The problem is that in case the console application throws an
exception Windows pops up a message that the console application "has
encountered a problem and needs to close". As it runs on a web server,
that is a very unfavourable situation.

I should say by using "Process.StartInfo.RedirectStandardError = true"
the Windows popup was disabled. Sadly, it is not.

Therefore I'm looking for a solution to suppress the Windows popup.

Instead of a windows setting I'd appreciate a programmable solution or
at least a new suggestion as how to call a console application out of
another application and catching its exceptions or read the
exception's text without getting that troublesome popup.

Thanks in advance!
 
Back
Top