473,396 Members | 1,689 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

Console application process question

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
Nov 16 '05 #1
4 5919
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" <hk***@hotmail.com> wrote in message
news:eo**************@TK2MSFTNGP09.phx.gbl...
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


Nov 16 '05 #2
jam
Thanks, I am changing it

"Dmitriy Lapshin [C# / .NET MVP]" <x-****@no-spam-please.hotpop.com> ¦b¶l¥ó
news:%2***************@TK2MSFTNGP10.phx.gbl ¤¤¼¶¼g...
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" <hk***@hotmail.com> wrote in message
news:eo**************@TK2MSFTNGP09.phx.gbl...
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

Nov 16 '05 #3
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 [C# / .NET MVP]" <x-****@no-spam-please.hotpop.com> ¦b¶l¥ó
news:%2***************@TK2MSFTNGP10.phx.gbl ¤¤¼¶¼g...
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" <hk***@hotmail.com> wrote in message
news:eo**************@TK2MSFTNGP09.phx.gbl...
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

Nov 16 '05 #4
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" <hk***@hotmail.com> wrote in message
news:e5**************@TK2MSFTNGP11.phx.gbl...
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]" <x-****@no-spam-please.hotpop.com>
¦b¶l¥ó
news:%2***************@TK2MSFTNGP10.phx.gbl ¤¤¼¶¼g...
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" <hk***@hotmail.com> wrote in message
news:eo**************@TK2MSFTNGP09.phx.gbl...
> 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
>
>



Nov 16 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Oz | last post by:
This is long. Bear with me, as I will really go through all the convoluted stuff that shows there is a problem with streams (at least when used to redirect stdout). The basic idea is that my...
5
by: Barry Mossman | last post by:
Hi, can I detect whether my class is running within the context of a Console application, vs say a WinForm's application ? also does anyone know whether the compiler or runtime is smart enough...
1
by: Stephen Miller | last post by:
On my development machine (where the group 'Everyone' has full access to every directory), the following code successfully shells to a console application: Dim objShell As...
1
by: chad | last post by:
Hi, I am using Process.Start() to call a console application from ASP.NET page. When the code is executed, the Console application is opened. When it is done, it should have been terminated but...
6
by: tony | last post by:
Hello! When you have windows forms you have the same possibility as when you have a Console application to use Console.Writeln to write whatever on the screen. Now to my question: Is it...
10
by: Stephany Young | last post by:
When one uses the System.Diagnostics.Process.Start method to launch a common or garden Console application, one can set the WindowStyle property of the StartInfo object to ProcessWindowStyle.Hidden...
5
by: =?Utf-8?B?VkIgSm9ubmll?= | last post by:
How can I send the Enter or Return keystroke to a VB.Net 2005 console application? -- Coding in Sunny Central Florida
12
by: Dilip | last post by:
Hi All I have a server based C# console application. This application must hide its console window when its launched out on the field. So I dutifully P/Invoke'd FindWindow/ShowWindow...
5
by: =?Utf-8?B?SmFtZXMgV29uZw==?= | last post by:
Dear all, I'd like to know if there is any method to minimize command mode window when a console program is running. In my case, there are several console programs which run periodically in...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.