Hello all,
I am trying to exectute a simple batch file from a C# application and I am running into some trouble. Basically, my code compiles fine, but when I run it, the batch file is never executed. I am simply trying to run a code sample that I received from another website and I am curious to know if this is a coding or machine related issue. Your thoughts would be most appreciated. Here is the code snippet:
using System;
using System.Text;
using System.Diagnostics;
namespace CallBatchFile
{
class Program
{
static void Main(string[] args)
{
Process p = new Process();
try
{
string targetDir;
targetDir = string
p.StartInfo.UseShellExecute = true;
p.StartInfo.WorkingDirectory = targetDir;
p.StartInfo.FileName = "MyBatchFile.bat";
p.StartInfo.Arguments = string.Format("C-Sharp Console application");
p.StartInfo.CreateNoWindow = false;
p.Start();
p.WaitForExit();
}
catch (Exception ex)
{
Console.WriteLine("Exception Occurred :{0},{1}", ex.Message,ex.StackTrace.ToString());
}
}
}
}