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?
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?