protected string ExecuteBat(string ExecutableFileName, string Arguments, double TimeoutSeconds = -1)
{
var Process = new System.Diagnostics.Process(); // Declare New Process
//proc.StartInfo.FileName = fileName;
//proc.StartInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
//proc.StartInfo.CreateNoWindow = true;
Process.StartInfo.FileName = ExecutableFileName;
Process.StartInfo.Arguments = Arguments;
Process.StartInfo.RedirectStandardError = true;
Process.StartInfo.RedirectStandardOutput = true;
Process.StartInfo.UseShellExecute = false;
Process.Start();
if (TimeoutSeconds < 0)
{
Process.WaitForExit();
}
else
{
Process.WaitForExit((int)TimeSpan.FromSeconds(TimeoutSeconds).TotalMilliseconds);
}
var ErrorMessage = Process.StandardError.ReadToEnd();
Process.WaitForExit();
var OutputMessage = Process.StandardOutput.ReadToEnd();
Process.WaitForExit();
Process.Start();
Process.WaitForExit();
return ErrorMessage + OutputMessage;
}