471,604 Members | 1,357 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,604 software developers and data experts.

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 4539
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
1 post views Thread by XIAOLAOHU | last post: by
reply views Thread by leo001 | last post: by
reply views Thread by MichaelMortimer | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.