Click here to Skip to main content
15,891,833 members
Please Sign up or sign in to vote.
3.00/5 (1 vote)
See more:
hi,


command prompt returns the output for xcopy command using below command.

> xcopy "d:\01-Oct-2013" "E:\" /e/y/I >xcopy.out


the output file created in particular location.


i need the output file in C# code.


startInfo.Arguments = "\"" + SolutionDirectory + "\"" + " " + "\"" + TargetDirectory + "\"" + @" /e /y /I ";

how can i get the output file using c# code.

thanks in advance....
Posted

Hi sankmahesh,

Try setting these startInfo properties: UseShellExecute = false and
RedirectStandardOutput = true. Then you can do something like:
C#
myProcess.Start();
while (!myProcess.StandardOutput.EndOfStream) {
    string line = myProcess.StandardOutput.ReadLine();
    // do something with it (write to file, parse, or whatever you need to)
}


Hope it helps,
--V.Lorz
 
Share this answer
 
Comments
sankmahesh 5-Nov-13 3:24am    
thank you for your reply..

i need another solution..

i want to copy two location..


xcopy src desc1 desc2..

is that possible??
V.Lorz 5-Nov-13 3:42am    
Copy the same file to two different locations? Yes, it's possible.

Take a look into Segey's solution for a better than xcopy approach.
sankmahesh 5-Nov-13 4:01am    
sorry that links are not open for me..

pls can you provide the proper solution
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
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900