469,282 Members | 2,025 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,282 developers. It's quick & easy.

Issue with using DOS commands in C#

I am using following code

string src = "C:\Source";
string dest = "C:\Destination";
copyCmdStr = "XCOPY "+ src + " "+ dest;
ProcessStartInfo processInfo = new ProcessStartInfo("CMD.Exe");
processInfo.Arguments = copyCmdStr;
processInfo.UseShellExecute = false;
processInfo.CreateNoWindow = true;
Process.Start(processInfo);

Nothing happens when this code is executed. Please help

Dec 21 '06 #1
3 4500
Ravichandra wrote:
I am using following code

string src = "C:\Source";
string dest = "C:\Destination";
copyCmdStr = "XCOPY "+ src + " "+ dest;
ProcessStartInfo processInfo = new ProcessStartInfo("CMD.Exe");
processInfo.Arguments = copyCmdStr;
processInfo.UseShellExecute = false;
processInfo.CreateNoWindow = true;
Process.Start(processInfo);

Nothing happens when this code is executed. Please help
My first question is why are you using xcopy from within a C# app to copy a
file? Go with System.IO.File.Copy(src, dest); and you're done. If those
are directories, then get the files in the directory, create the target,
then copy the files over.
--
Tom Porterfield

Dec 21 '06 #2
This is the first part of the code I am writing. In general, the
requirement is to support all the 20 odd switches of the Xcopy command.

Tom Porterfield wrote:
Ravichandra wrote:
I am using following code

string src = "C:\Source";
string dest = "C:\Destination";
copyCmdStr = "XCOPY "+ src + " "+ dest;
ProcessStartInfo processInfo = new ProcessStartInfo("CMD.Exe");
processInfo.Arguments = copyCmdStr;
processInfo.UseShellExecute = false;
processInfo.CreateNoWindow = true;
Process.Start(processInfo);

Nothing happens when this code is executed. Please help

My first question is why are you using xcopy from within a C# app to copy a
file? Go with System.IO.File.Copy(src, dest); and you're done. If those
are directories, then get the files in the directory, create the target,
then copy the files over.
--
Tom Porterfield
Dec 21 '06 #3
Ravichandra wrote:
This is the first part of the code I am writing. In general, the
requirement is to support all the 20 odd switches of the Xcopy command.
Then simply make the two following changes:

//...
copyCmdStr = src + " "+ dest;
//...
ProcessStartInfo processInfo = new ProcessStartInfo("xcopy.exe");
//...
Or leave the processstartinfo as cmd.exe and change the copyCmdStr to "/c
xcopy.exe " + src + " "+ dest;

I would go with the former as xcopy is the real process you want to start,
not cmd.exe.
--
Tom Porterfield

Dec 21 '06 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by Ravindran Pandian | last post: by
6 posts views Thread by Christopher Murtagh | last post: by
reply views Thread by Patrick Finnegan | last post: by
6 posts views Thread by Dario Di Bella | last post: by
3 posts views Thread by gmtonyhoyt | last post: by
4 posts views Thread by Paul | last post: by
13 posts views Thread by souissipro | last post: by
2 posts views Thread by kyosohma | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.