Console application process question

J

jam

Dear All,

I have a command process running xcopy in console, and now I want to execute
the program Rsync After the files are copied...how could i do??

Process p10=new Process();
p10.StartInfo.FileName = "cmd.exe";
p10.StartInfo.UseShellExecute = false;
// p.StartInfo.CreateNoWindow = true;
p10.StartInfo.RedirectStandardInput = true;
p10.StartInfo.RedirectStandardOutput = true;
p10.StartInfo.RedirectStandardError = true;
p10.Start();

p10.StandardInput.WriteLine("xcopy "+IISDir+"\\Chi\\swf
"+RootDir+"\\Chi\\swf /h /i /e /r /y ");
Console.WriteLine("xcopy "+IISDir+"\\Chi\\swf "+RootDir+"\\Chi\\swf /h
/i /e /r /y ");
p10.Close();
WriteToMessageFile("\nCopy Chi Folder is Done at "+DateTime.Now);

Process p11=new Process();
p11.StartInfo.FileName = "cmd.exe";
p11.StartInfo.UseShellExecute = false;
// p.StartInfo.CreateNoWindow = true;
p11.StartInfo.RedirectStandardInput = true;
p11.StartInfo.RedirectStandardOutput = true;
p11.StartInfo.RedirectStandardError = true;
p11.Start();
p11.StandardInput.WriteLine("run rsync");
Console.WriteLine("Rsync running");
p11.Close();
WriteToMessageFile("\nRsync is Done at "+DateTime.Now);

But I cannot make it wait for p10 to finish then start p11, how could it do?
this cannot be done with setting a time for p11 to start cos the file may
build up in swf folder after a while, I mean the copying time may become
longer.....

Jam
thanks
 
D

Dmitriy Lapshin [C# / .NET MVP]

Jam,

You overcomplicate things! You can start xcopy.exe and rsync.exe as
processes by themselves, you don't even need to use cmd.exe:

Process p10=new Process();
p10.StartInfo.FileName = "xcopy";
p10.StartInfo.UseShellExecute = true;
p10.StartInfo.Arguments = IISDir+"\\Chi\\swf"+RootDir+"\\Chi\\swf /h /i /e
/r /y ";
p10.Start();
p10.WaitForExit();

Process p11=new Process();
p11.StartInfo.FileName = "run rsync";
p11.StartInfo.UseShellExecute = true;
p11.Start();
p11.WaitForExit();
 
J

jam

Thanks, I am changing it

Dmitriy Lapshin said:
Jam,

You overcomplicate things! You can start xcopy.exe and rsync.exe as
processes by themselves, you don't even need to use cmd.exe:

Process p10=new Process();
p10.StartInfo.FileName = "xcopy";
p10.StartInfo.UseShellExecute = true;
p10.StartInfo.Arguments = IISDir+"\\Chi\\swf"+RootDir+"\\Chi\\swf /h /i /e
/r /y ";
p10.Start();
p10.WaitForExit();

Process p11=new Process();
p11.StartInfo.FileName = "run rsync";
p11.StartInfo.UseShellExecute = true;
p11.Start();
p11.WaitForExit();

--
Sincerely,
Dmitriy Lapshin [C# / .NET MVP]
Bring the power of unit testing to the VS .NET IDE today!
http://www.x-unity.net/teststudio.aspx

jam said:
Dear All,

I have a command process running xcopy in console, and now I want to
execute
the program Rsync After the files are copied...how could i do??

Process p10=new Process();
p10.StartInfo.FileName = "cmd.exe";
p10.StartInfo.UseShellExecute = false;
// p.StartInfo.CreateNoWindow = true;
p10.StartInfo.RedirectStandardInput = true;
p10.StartInfo.RedirectStandardOutput = true;
p10.StartInfo.RedirectStandardError = true;
p10.Start();

p10.StandardInput.WriteLine("xcopy "+IISDir+"\\Chi\\swf
"+RootDir+"\\Chi\\swf /h /i /e /r /y ");
Console.WriteLine("xcopy "+IISDir+"\\Chi\\swf "+RootDir+"\\Chi\\swf /h
/i /e /r /y ");
p10.Close();
WriteToMessageFile("\nCopy Chi Folder is Done at "+DateTime.Now);

Process p11=new Process();
p11.StartInfo.FileName = "cmd.exe";
p11.StartInfo.UseShellExecute = false;
// p.StartInfo.CreateNoWindow = true;
p11.StartInfo.RedirectStandardInput = true;
p11.StartInfo.RedirectStandardOutput = true;
p11.StartInfo.RedirectStandardError = true;
p11.Start();
p11.StandardInput.WriteLine("run rsync");
Console.WriteLine("Rsync running");
p11.Close();
WriteToMessageFile("\nRsync is Done at "+DateTime.Now);

But I cannot make it wait for p10 to finish then start p11, how could it
do?
this cannot be done with setting a time for p11 to start cos the file may
build up in swf folder after a while, I mean the copying time may become
longer.....

Jam
thanks
 
J

jam

Thanks, It works perfectly,

So now I wanna ask, how could I know if it has error? like if the folder is
not the correct one, like, I point to d:\(which doesn't exist), I wanna
capture the error, write to a log and then exit the whole process (stop the
coming process too)

thanks all for raplying


Dmitriy Lapshin said:
Jam,

You overcomplicate things! You can start xcopy.exe and rsync.exe as
processes by themselves, you don't even need to use cmd.exe:

Process p10=new Process();
p10.StartInfo.FileName = "xcopy";
p10.StartInfo.UseShellExecute = true;
p10.StartInfo.Arguments = IISDir+"\\Chi\\swf"+RootDir+"\\Chi\\swf /h /i /e
/r /y ";
p10.Start();
p10.WaitForExit();

Process p11=new Process();
p11.StartInfo.FileName = "run rsync";
p11.StartInfo.UseShellExecute = true;
p11.Start();
p11.WaitForExit();

--
Sincerely,
Dmitriy Lapshin [C# / .NET MVP]
Bring the power of unit testing to the VS .NET IDE today!
http://www.x-unity.net/teststudio.aspx

jam said:
Dear All,

I have a command process running xcopy in console, and now I want to
execute
the program Rsync After the files are copied...how could i do??

Process p10=new Process();
p10.StartInfo.FileName = "cmd.exe";
p10.StartInfo.UseShellExecute = false;
// p.StartInfo.CreateNoWindow = true;
p10.StartInfo.RedirectStandardInput = true;
p10.StartInfo.RedirectStandardOutput = true;
p10.StartInfo.RedirectStandardError = true;
p10.Start();

p10.StandardInput.WriteLine("xcopy "+IISDir+"\\Chi\\swf
"+RootDir+"\\Chi\\swf /h /i /e /r /y ");
Console.WriteLine("xcopy "+IISDir+"\\Chi\\swf "+RootDir+"\\Chi\\swf /h
/i /e /r /y ");
p10.Close();
WriteToMessageFile("\nCopy Chi Folder is Done at "+DateTime.Now);

Process p11=new Process();
p11.StartInfo.FileName = "cmd.exe";
p11.StartInfo.UseShellExecute = false;
// p.StartInfo.CreateNoWindow = true;
p11.StartInfo.RedirectStandardInput = true;
p11.StartInfo.RedirectStandardOutput = true;
p11.StartInfo.RedirectStandardError = true;
p11.Start();
p11.StandardInput.WriteLine("run rsync");
Console.WriteLine("Rsync running");
p11.Close();
WriteToMessageFile("\nRsync is Done at "+DateTime.Now);

But I cannot make it wait for p10 to finish then start p11, how could it
do?
this cannot be done with setting a time for p11 to start cos the file may
build up in swf folder after a while, I mean the copying time may become
longer.....

Jam
thanks
 
D

Dmitriy Lapshin [C# / .NET MVP]

You can analyze process' exit code, and/or you can redirect process'
standard output and parse it.

--
Sincerely,
Dmitriy Lapshin [C# / .NET MVP]
Bring the power of unit testing to the VS .NET IDE today!
http://www.x-unity.net/teststudio.aspx

jam said:
Thanks, It works perfectly,

So now I wanna ask, how could I know if it has error? like if the folder
is
not the correct one, like, I point to d:\(which doesn't exist), I wanna
capture the error, write to a log and then exit the whole process (stop
the
coming process too)

thanks all for raplying


"Dmitriy Lapshin [C# / .NET MVP]" <[email protected]>
¦b¶l¥ó
Jam,

You overcomplicate things! You can start xcopy.exe and rsync.exe as
processes by themselves, you don't even need to use cmd.exe:

Process p10=new Process();
p10.StartInfo.FileName = "xcopy";
p10.StartInfo.UseShellExecute = true;
p10.StartInfo.Arguments = IISDir+"\\Chi\\swf"+RootDir+"\\Chi\\swf /h /i
/e
/r /y ";
p10.Start();
p10.WaitForExit();

Process p11=new Process();
p11.StartInfo.FileName = "run rsync";
p11.StartInfo.UseShellExecute = true;
p11.Start();
p11.WaitForExit();

--
Sincerely,
Dmitriy Lapshin [C# / .NET MVP]
Bring the power of unit testing to the VS .NET IDE today!
http://www.x-unity.net/teststudio.aspx

jam said:
Dear All,

I have a command process running xcopy in console, and now I want to
execute
the program Rsync After the files are copied...how could i do??

Process p10=new Process();
p10.StartInfo.FileName = "cmd.exe";
p10.StartInfo.UseShellExecute = false;
// p.StartInfo.CreateNoWindow = true;
p10.StartInfo.RedirectStandardInput = true;
p10.StartInfo.RedirectStandardOutput = true;
p10.StartInfo.RedirectStandardError = true;
p10.Start();

p10.StandardInput.WriteLine("xcopy "+IISDir+"\\Chi\\swf
"+RootDir+"\\Chi\\swf /h /i /e /r /y ");
Console.WriteLine("xcopy "+IISDir+"\\Chi\\swf "+RootDir+"\\Chi\\swf /h
/i /e /r /y ");
p10.Close();
WriteToMessageFile("\nCopy Chi Folder is Done at "+DateTime.Now);

Process p11=new Process();
p11.StartInfo.FileName = "cmd.exe";
p11.StartInfo.UseShellExecute = false;
// p.StartInfo.CreateNoWindow = true;
p11.StartInfo.RedirectStandardInput = true;
p11.StartInfo.RedirectStandardOutput = true;
p11.StartInfo.RedirectStandardError = true;
p11.Start();
p11.StandardInput.WriteLine("run rsync");
Console.WriteLine("Rsync running");
p11.Close();
WriteToMessageFile("\nRsync is Done at "+DateTime.Now);

But I cannot make it wait for p10 to finish then start p11, how could
it
do?
this cannot be done with setting a time for p11 to start cos the file may
build up in swf folder after a while, I mean the copying time may
become
longer.....

Jam
thanks
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top