Try something like this:
StreamReader outputReader = null;
StreamReader errorReader = null;
bool success = false;
using (Process process = new Process()
{
StartInfo = new ProcessStartInfo()
{
RedirectStandardError = true,
RedirectStandardInput = true,
RedirectStandardOutput = true,
UseShellExecute = false,
CreateNoWindow = true,
FileName = "xcopy",
Arguments = @"SourceFile c:\DestinationFile /e /y /I"
}
})
{
try
{
bool processStarted = process.Start();
if (processStarted)
{
outputReader = process.StandardOutput;
errorReader = process.StandardError;
process.WaitForExit();
success = (process.ExitCode == 0);
string displayText = string.Concat("Output", Environment.NewLine, "==============", Environment.NewLine);
displayText = string.Concat(displayText, outputReader.ReadToEnd());
displayText = string.Concat(displayText, Environment.NewLine, "Error", Environment.NewLine, "==============", Environment.NewLine;
displayText += errorReader.ReadToEnd();
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
finally
{
if (outputReader != null)
{
outputReader.Close();
}
if (errorReader != null)
{
errorReader.Close();
}
}
}
if (success)
{
}
else
{
}