Issue using Process.Start() to execute command line statement

Issue using Process.Start() to execute command line statement

am 25.10.2007 07:21:02 von JobLot

I am having issues copying files from network drive to local machine using
xcopy. The following code works alright for a console application, but as
soon as i call this code in Form Load event of windows application it does
not work. I am confused here, it copies files in a console application, but
not windows app

ProcessStartInfo info = new ProcessStartInfo("xcopy", "");
info.FileName = "xcopy";
info.Arguments = string.Format("\"{0}\" \"{1}\" /r/e/c/i/y/d",
@"\\melsrv01\Public\Templates\Austock Office\.",
@"C:\temp\Test Images");
info.UseShellExecute = false;
info.RedirectStandardOutput = true;

Process process = Process.Start(info);
string result = process.StandardOutput.ReadToEnd();
process.WaitForExit();
Console.WriteLine(result);
//MessageBox.Show(result);


Please help. Thanks

Re: Issue using Process.Start() to execute command line statement

am 25.10.2007 17:59:46 von John Vottero

"Job Lot" wrote in message
news:BF4A8CC2-8429-4C99-86BB-57E41894DC81@microsoft.com...
>I am having issues copying files from network drive to local machine using
> xcopy. The following code works alright for a console application, but as
> soon as i call this code in Form Load event of windows application it does
> not work. I am confused here, it copies files in a console application,
> but
> not windows app

What do you mean by "does not work"?

Re: Issue using Process.Start() to execute command line statement

am 26.10.2007 02:54:00 von JobLot

It copies the file from network drive to local machine in the console
application, but does not copy anything when the same code is used in Form
Load event of the windows application.


"John Vottero" wrote:

> "Job Lot" wrote in message
> news:BF4A8CC2-8429-4C99-86BB-57E41894DC81@microsoft.com...
> >I am having issues copying files from network drive to local machine using
> > xcopy. The following code works alright for a console application, but as
> > soon as i call this code in Form Load event of windows application it does
> > not work. I am confused here, it copies files in a console application,
> > but
> > not windows app
>
> What do you mean by "does not work"?
>
>

Re: Issue using Process.Start() to execute command line statement

am 26.10.2007 12:15:05 von hpassant

It's a quirk of xcopy.exe; when you redirect output you have to
redirect input too. If you don't, it immediately (and silently) quits
right after startup.

Re: Issue using Process.Start() to execute command line statement

am 26.10.2007 12:29:37 von Marc Gravell

As a complete aside - can I recommend robocopy as a replacement to
xcopy? You can download from Microsoft, or it is included in Vista; it
does more, does it better, and does it quicker.

Marc

Re: Issue using Process.Start() to execute command line statement

am 28.10.2007 23:53:00 von JobLot

Thanks hpassant@gmail.com that did the trick. I didn't find any mention of
that in MSDN !!!

"hpassant@gmail.com" wrote:

> It's a quirk of xcopy.exe; when you redirect output you have to
> redirect input too. If you don't, it immediately (and silently) quits
> right after startup.
>
>