There are three questions in this
- How do I execute an external command
- How to receive the output
- How do I parse the result
1: Running a DOS - Command is pretty easy:
System.Diagnostics.Process.Start("xcopy","source1 dest1");
2: Now you have two possibilities to retrieve the output. The first is to change your command to "xcopy source1 dest1 >output.txt
" and read the txt-file afterwards. The second is to run the thread differently:
var proc = new Process {
StartInfo = new ProcessStartInfo {
FileName = "xcopy",
Arguments = "source1 dest1",
RedirectStandardOutput = true
}
};
proc.Start();
string response=string.Empty;
while (!proc.StandardOutput.EndOfStream) {
response += proc.StandardOutput.ReadLine();
}
now response
contains the response of your copy command. Now all you have to do is to parse the return value (3).
If you got problems with the last part, search on SO or write a new question for it.