473,791 Members | 2,949 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.F ileName = "cmd.exe";
p10.StartInfo.U seShellExecute = false;
// p.StartInfo.Cre ateNoWindow = true;
p10.StartInfo.R edirectStandard Input = true;
p10.StartInfo.R edirectStandard Output = true;
p10.StartInfo.R edirectStandard Error = true;
p10.Start();

p10.StandardInp ut.WriteLine("x copy "+IISDir+"\\Chi \\swf
"+RootDir+"\\Ch i\\swf /h /i /e /r /y ");
Console.WriteLi ne("xcopy "+IISDir+"\\Chi \\swf "+RootDir+"\\Ch i\\swf /h
/i /e /r /y ");
p10.Close();
WriteToMessageF ile("\nCopy Chi Folder is Done at "+DateTime.Now) ;

Process p11=new Process();
p11.StartInfo.F ileName = "cmd.exe";
p11.StartInfo.U seShellExecute = false;
// p.StartInfo.Cre ateNoWindow = true;
p11.StartInfo.R edirectStandard Input = true;
p11.StartInfo.R edirectStandard Output = true;
p11.StartInfo.R edirectStandard Error = true;
p11.Start();
p11.StandardInp ut.WriteLine("r un rsync");
Console.WriteLi ne("Rsync running");
p11.Close();
WriteToMessageF ile("\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 5949
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.F ileName = "xcopy";
p10.StartInfo.U seShellExecute = true;
p10.StartInfo.A rguments = IISDir+"\\Chi\\ swf"+RootDir+"\ \Chi\\swf /h /i /e
/r /y ";
p10.Start();
p10.WaitForExit ();

Process p11=new Process();
p11.StartInfo.F ileName = "run rsync";
p11.StartInfo.U seShellExecute = 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******** ******@TK2MSFTN GP09.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.F ileName = "cmd.exe";
p10.StartInfo.U seShellExecute = false;
// p.StartInfo.Cre ateNoWindow = true;
p10.StartInfo.R edirectStandard Input = true;
p10.StartInfo.R edirectStandard Output = true;
p10.StartInfo.R edirectStandard Error = true;
p10.Start();

p10.StandardInp ut.WriteLine("x copy "+IISDir+"\\Chi \\swf
"+RootDir+"\\Ch i\\swf /h /i /e /r /y ");
Console.WriteLi ne("xcopy "+IISDir+"\\Chi \\swf "+RootDir+"\\Ch i\\swf /h
/i /e /r /y ");
p10.Close();
WriteToMessageF ile("\nCopy Chi Folder is Done at "+DateTime.Now) ;

Process p11=new Process();
p11.StartInfo.F ileName = "cmd.exe";
p11.StartInfo.U seShellExecute = false;
// p.StartInfo.Cre ateNoWindow = true;
p11.StartInfo.R edirectStandard Input = true;
p11.StartInfo.R edirectStandard Output = true;
p11.StartInfo.R edirectStandard Error = true;
p11.Start();
p11.StandardInp ut.WriteLine("r un rsync");
Console.WriteLi ne("Rsync running");
p11.Close();
WriteToMessageF ile("\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.c om> ¦b¶l¥ó
news:%2******** *******@TK2MSFT NGP10.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.F ileName = "xcopy";
p10.StartInfo.U seShellExecute = true;
p10.StartInfo.A rguments = IISDir+"\\Chi\\ swf"+RootDir+"\ \Chi\\swf /h /i /e
/r /y ";
p10.Start();
p10.WaitForExit ();

Process p11=new Process();
p11.StartInfo.F ileName = "run rsync";
p11.StartInfo.U seShellExecute = 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******** ******@TK2MSFTN GP09.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.F ileName = "cmd.exe";
p10.StartInfo.U seShellExecute = false;
// p.StartInfo.Cre ateNoWindow = true;
p10.StartInfo.R edirectStandard Input = true;
p10.StartInfo.R edirectStandard Output = true;
p10.StartInfo.R edirectStandard Error = true;
p10.Start();

p10.StandardInp ut.WriteLine("x copy "+IISDir+"\\Chi \\swf
"+RootDir+"\\Ch i\\swf /h /i /e /r /y ");
Console.WriteLi ne("xcopy "+IISDir+"\\Chi \\swf "+RootDir+"\\Ch i\\swf /h /i /e /r /y ");
p10.Close();
WriteToMessageF ile("\nCopy Chi Folder is Done at "+DateTime.Now) ;

Process p11=new Process();
p11.StartInfo.F ileName = "cmd.exe";
p11.StartInfo.U seShellExecute = false;
// p.StartInfo.Cre ateNoWindow = true;
p11.StartInfo.R edirectStandard Input = true;
p11.StartInfo.R edirectStandard Output = true;
p11.StartInfo.R edirectStandard Error = true;
p11.Start();
p11.StandardInp ut.WriteLine("r un rsync");
Console.WriteLi ne("Rsync running");
p11.Close();
WriteToMessageF ile("\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.c om> ¦b¶l¥ó
news:%2******** *******@TK2MSFT NGP10.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.F ileName = "xcopy";
p10.StartInfo.U seShellExecute = true;
p10.StartInfo.A rguments = IISDir+"\\Chi\\ swf"+RootDir+"\ \Chi\\swf /h /i /e
/r /y ";
p10.Start();
p10.WaitForExit ();

Process p11=new Process();
p11.StartInfo.F ileName = "run rsync";
p11.StartInfo.U seShellExecute = 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******** ******@TK2MSFTN GP09.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.F ileName = "cmd.exe";
p10.StartInfo.U seShellExecute = false;
// p.StartInfo.Cre ateNoWindow = true;
p10.StartInfo.R edirectStandard Input = true;
p10.StartInfo.R edirectStandard Output = true;
p10.StartInfo.R edirectStandard Error = true;
p10.Start();

p10.StandardInp ut.WriteLine("x copy "+IISDir+"\\Chi \\swf
"+RootDir+"\\Ch i\\swf /h /i /e /r /y ");
Console.WriteLi ne("xcopy "+IISDir+"\\Chi \\swf "+RootDir+"\\Ch i\\swf /h /i /e /r /y ");
p10.Close();
WriteToMessageF ile("\nCopy Chi Folder is Done at "+DateTime.Now) ;

Process p11=new Process();
p11.StartInfo.F ileName = "cmd.exe";
p11.StartInfo.U seShellExecute = false;
// p.StartInfo.Cre ateNoWindow = true;
p11.StartInfo.R edirectStandard Input = true;
p11.StartInfo.R edirectStandard Output = true;
p11.StartInfo.R edirectStandard Error = true;
p11.Start();
p11.StandardInp ut.WriteLine("r un rsync");
Console.WriteLi ne("Rsync running");
p11.Close();
WriteToMessageF ile("\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******** ******@TK2MSFTN GP11.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.c om>
¦b¶l¥ó
news:%2******** *******@TK2MSFT NGP10.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.F ileName = "xcopy";
p10.StartInfo.U seShellExecute = true;
p10.StartInfo.A rguments = IISDir+"\\Chi\\ swf"+RootDir+"\ \Chi\\swf /h /i
/e
/r /y ";
p10.Start();
p10.WaitForExit ();

Process p11=new Process();
p11.StartInfo.F ileName = "run rsync";
p11.StartInfo.U seShellExecute = 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******** ******@TK2MSFTN GP09.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.F ileName = "cmd.exe";
> p10.StartInfo.U seShellExecute = false;
> // p.StartInfo.Cre ateNoWindow = true;
> p10.StartInfo.R edirectStandard Input = true;
> p10.StartInfo.R edirectStandard Output = true;
> p10.StartInfo.R edirectStandard Error = true;
> p10.Start();
>
> p10.StandardInp ut.WriteLine("x copy "+IISDir+"\\Chi \\swf
> "+RootDir+"\\Ch i\\swf /h /i /e /r /y ");
> Console.WriteLi ne("xcopy "+IISDir+"\\Chi \\swf "+RootDir+"\\Ch i\\swf /h > /i /e /r /y ");
> p10.Close();
> WriteToMessageF ile("\nCopy Chi Folder is Done at "+DateTime.Now) ;
>
> Process p11=new Process();
> p11.StartInfo.F ileName = "cmd.exe";
> p11.StartInfo.U seShellExecute = false;
> // p.StartInfo.Cre ateNoWindow = true;
> p11.StartInfo.R edirectStandard Input = true;
> p11.StartInfo.R edirectStandard Output = true;
> p11.StartInfo.R edirectStandard Error = true;
> p11.Start();
> p11.StandardInp ut.WriteLine("r un rsync");
> Console.WriteLi ne("Rsync running");
> p11.Close();
> WriteToMessageF ile("\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
5388
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 application (VB.NET) will start a process, redirect its stdout and capture that process' output, displaying it in a window. I've written a component for this, and a test application for the component. It allows me to specify a command to execute,...
5
11259
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 to avoid the overhead of writing to the console if it is not visible, eg I am running inside a WinForm application. thanks
1
1930
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 System.Diagnostics.Process = New System.Diagnostics.Process() With objShell .StartInfo.FileName = "C:\Project\MyApp\MyApp.exe" .StartInfo.Arguments = " 123" .StartInfo.WorkingDirectory = "C:\Project\MyApp\"
1
2400
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 it is not. I have placed WaitForExit(20000) to limit the execution time to 20 seconds and if it does not terminate then it will be forced close. The question is why wouldn't the application exit by itself when it is done as it should be (it was...
6
5716
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 possible to use Console.Writeln when you have a Webservice. I don't think it's possible but just to be sure I ask you?
10
6350
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 so that the window for the Console application is not visible. However, when using some of the 'advanced' properties of the StartInfo object, like Username, Password and Domain, the WindowsStyle property of the StartInfo object is ignored....
5
546
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
6543
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 combination to hide the console window at launch time. The application (for legacy reasons) hangs around by waiting on an old- fashioned Console.ReadLine() statement.
5
10779
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 server. Now, every console program instance will open a command mode window and they occupy the whole screen. I want to minimize all of them and maximize it if neccessary by manual. Is it possible and how to do it? I'm using VB.NET 2005. ...
0
9515
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10427
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10207
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10155
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9029
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6776
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5431
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5559
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3718
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.