
Untitled
By: a guest on
Aug 12th, 2012 | syntax:
None | size: 1.11 KB | hits: 8 | expires: Never
Executing batch file with ProcessStartInfo
internal bool ExecuteBatchFile(string fileName, int executionTime)
{
var exitCode = -1;
var error = string.Empty;
try
{
var hubStartInfo = new ProcessStartInfo
{
CreateNoWindow = false,
FileName = fileName,
UseShellExecute = false
};
var process = new Process { StartInfo = hubStartInfo };
process.Start();
process.WaitForExit(executionTime);
if (process.HasExited)
{
exitCode = process.ExitCode;
if (exitCode == 0)
{
return true;
}
error = process.StandardError.ReadToEnd();
}
else
{
return true;
}
return false;
}
catch (Exception e)
{
return false;
}
}
private void simpleRun_Click(object sender, System.EventArgs e)
{
System.Diagnostics.Process.Start(@"C:listfiles.bat");
}