Fetching standard output is easy if Process.StartInfo.UseShellExecute = false
. However, in my case, UseShellExecute must remain true. The reason is that I am kicking off an .exe that happens to be in the PATH but not in the current working directory.
Here is the reason I can't use UseShellExecute = false
:
var psi = new ProcessStartInfo("cleancss", "--help")
{
WorkingDirectory = @"C:\SomeRandomDirectory",
UseShellExecute = false,
RedirectStandardOutput = true,
RedirectStandardInput = true
};
Process cssClean = Process.Start(psi); //blows up with The system cannot find the file specified
It correctly blows up because UseShellExecute = false
requires an absolute path. I do not have an absolute path.
If I set UseShellExecute = true
in the above sample, it tells me that redirecting standard output doesn't work in this scenario.
How do I get the standard output when UseShellExecute is true?