PRB - UseShellExecute option does not return STD-ERR

G

Guest

PRB - UseShellExecute option does not return STD-ERR

Please help,

I'm using the Process class to start an external process that "may" fail,
for all kinds of reasons, but in particular, it may fail because it needs
DLLs in its path. Normally if one manually launched such a process it would
show a dialog denoting the DLL it could not find. When I use the Process
class and specify the following on the ProcessStartInfo, the STD-ERR and
STD-OUT do not return the error message.

===============================
Process_MyThingy = new System.Diagnostics.Process();
ProcessStartInfo_MyThingy = new System.Diagnostics.ProcessStartInfo();

ProcessStartInfo_MyThingy.FileName = csTargetPath;
ProcessStartInfo_MyThingy.RedirectStandardError = true;
ProcessStartInfo_MyThingy.RedirectStandardInput = true;
ProcessStartInfo_MyThingy.RedirectStandardOutput = true;
ProcessStartInfo_MyThingy.UseShellExecute = false;

Process_MyThingy.StartInfo = ProcessStartInfo_MyThingy;

if (!Process_MyThingy.Start())
{
csERR =
"The MyThingy object failed to start. The file may be corrupt
and/or somehow a " +
"previous instance of the MyThingy object is still running and
is preventing further " +
"instances from running";
throw(new Exception(csERR));
}

StreamReader_StdOut = Process_MyThingy.StandardOutput;
StreamReader_StdErr = Process_MyThingy.StandardError;

if (Process_MyThingy.HasExited && (Process_MyThingy.ExitCode != 0))
{
csERR = StreamReader_StdErr.ReadToEnd();

if (IsBlank(ref csERR))
{
csERR = StreamReader_StdOut.ReadToEnd();
}

if (IsBlank(ref csERR))
{
csERR =
"The MyThingy object has ended immediately after launching,
but it could not be " +
"examined to determine if it successfully started not. One
likely cause of this " +
"situation is that the MyThingy object is missing needed DLLs
and resources it " +
"needs in order to run";
}

throw(new Exception(csERR));
}
===============================

From that code snippet, if it is used to launch an EXE that will not be able
to find a needed DLL, such that the EXE would otherwise show the dialog
denoting the DLL it was missing, then the code snippet will not get any
feedback whatsoever in STD-OUT or STD-ERR.

By the way, the "IsBlank" function is a simply function that just checks to
see if a string is empty or only comprised of white-space characters like
\t\r\n, etc.

How can I get the DLL missing error without showing the dialog, and/or go
ahead and let the dialog show, but I still need to redirect the STD-IN, OUT,
and ERR?
 
N

Nicholas Paldino [.NET/C# MVP]

You are not going to get anything on STDOUT or STDERR if the program
shows a dialog. The dialog is not connected to the STDERR or STDOUT stream
in any way.

If you are looking for an error, then the program needs to provide it in
some way. You could look for a dialog with a specific title, but that's not
a very sure-fire way of getting the information you need.
 
G

Guest

Thanks for the reply,

But I'm confused. If I do not reroute the STD-IN/OUT/ERR, the "DLL missing
Error Dialog" shows. But when I do reroute STD-IN/OUT/ERR, the dialog does
not show. Why is that so? If the "Process" class would just let the dialog
show, everything would be wonderful.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top