I need to execute a shell command from c#
code and then log to a file the output of the shell.
The code i use to execute the shell command is:
using (var process = Process.Start(new ProcessStartInfo
{
FileName = fileName,
Arguments = arguments,
CreateNoWindow = false,
WindowStyle = ProcessWindowStyle.Normal,
RedirectStandardOutput = false,
UseShellExecute = true,
}))
{
// blocking wait for the process to end
process.WaitForExit();
}
I read other answers that change RedirectStandardOutput = true
and useShellExecute = false
so they can get console output with
string output = process.StandardOutput.ReadToEnd();
But this won't open the shell window.
Is there a way to display the command output to the console window and get that output?