Batch unter C#
Ein einfaches Snippet für Batch-Ausführung unter C-Sharp.
/// <summary>
/// starts a batch, DELETE!!!!!!
/// </summary>
/// <param name="arguments"></param>
/// <returns></returns>
private bool StartBatch(string arguments)
{
//string first = "/c ";
ProcessStartInfo startInfo = new ProcessStartInfo();
startInfo.FileName = @"cmd.exe";
startInfo.UseShellExecute = false;
startInfo.Arguments = /*first +*/ arguments;
startInfo.WindowStyle = ProcessWindowStyle.Hidden;
startInfo.RedirectStandardInput = true;
startInfo.RedirectStandardOutput = true;
startInfo.RedirectStandardError = true;
StreamReader outputReader = null;
StreamReader errorReader = null;
try
{
Process prc = Process.Start(startInfo);
outputReader = prc.StandardOutput;
errorReader = prc.StandardError;
prc.WaitForExit();
prc.Close();
string line = "";
string complete = "";
while((line = outputReader.ReadLine()) !=null)
{
complete += line;
}
MessageBox.Show(complete);
}
catch(Exception e)
{
MessageBox.Show(e.ToString());
return false;
}
return true;
}