I'm trying to execute a simple batch script from a C# program.
Here's a minimal example:
Batch file
TIMEOUT /T 30 >nul
EXIT /B 1
C# program
static void Main(string[] args)
{
Process process = new Process();
process.StartInfo.UseShellExecute = false;
process.StartInfo.RedirectStandardOutput = true;
process.StartInfo.CreateNoWindow = false;
process.StartInfo.FileName = "D:\\xxx.bat";
process.Start();
string output = process.StandardOutput.ReadToEnd();
bool exit = process.WaitForExit(120000);
Console.WriteLine(output);
}
Output
"\r\nC:\\Users\\xxx\\bin\\Debug>TIMEOUT /T 30 \r\n\r\nWaiting for 30 seconds, press a key to continue ...\r\n\r\nC:\\Users\\xxx\\bin\\Debug>EXIT /B 1 \r\n"
I'd expect the batch script to produce no output (due to nul redirection of the timeout command) but it still does. The output contains the program path and the command text. Why is that? (Is it outputting the script trace eg. like bash -x? Google doesn't tell me how/if it could be disabled)