If the you face a problem, sometimes a solution is to invert it. Indeed, why using "xcopy" at all? No, I understand that the problem is simple, your approach works, and you need a seemingly minor detail. It is really easy to solve. Not so fast though. You are trying to create a separate
process. And the processes are well isolated, and most of the applications are not designed for collaborations with other processes. So, why breaking through a closed door?
The most straightforward alternative is to implement xcopy functionality directly in your code using available .NET FCL methods. You have all you need, and you will need only for FCL methods:
http://msdn.microsoft.com/en-us/library/c1sez4sc.aspx[
^],
http://msdn.microsoft.com/en-us/library/07wt70x2.aspx[
^],
http://msdn.microsoft.com/en-us/library/54a0at6s.aspx[
^],
http://msdn.microsoft.com/en-us/library/system.io.file.copy.aspx[
^].
As you can see, everything is already created for you.
However, if you still want to use xcopy, the solution is redirection of
System.Diagnostics.Process.StandardOutput
and, just in case,
System.Diagnostics.Process.StandardError
. You will find the code sample with redirection here:
http://msdn.microsoft.com/en-us/library/system.diagnostics.process.standardoutput.aspx[
^].
Good luck,
—SA