Hi Yoavo,
here is how you would do that with a couple of the possible options you
might want to set:
using System.Diagnostics;
ProcessStartInfo psi = new System.Diagnostics.ProcessStartInfo();
//specify the nam andthe arguements you want to pass to the command prompt
psi.FileName = @"c:\test123.bat";
psi.Arguments = "1 2 3 4";
//if you don't want a console window popping up then set this property
pi.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
//Create new process and set the starting information
System.Diagnostics.Process p = new System.Diagnostics.Process();
p.StartInfo = psi;
//Set this so that you can tell when the process has completed
p.EnableRaisingEvents = true;
p.Start();
//wait until the process has completed
while(!p.HasExited)
{
System.Threading.Thread.Sleep(1000);
}
//check to see what the exit code was
if(p.ExitCode != 0)
{
//some error occurred
}
Hope that helps
Mark R Dawson
"Yoavo" wrote:
Hi,
I have a batch file "MyFile.bat", and I need to run it from a C#
application.
How do I do it ?
Yoav.