E
eva.monsen
I'm trying to run a .BAT file using System.Diagnostics.Process. I'm
having trouble getting Process.ExitCode to match up with what the .BAT
file returns.
Here are the contents of
C:\temp\ConsoleApplication1\ConsoleApplication1\test1.bat:
exit /B 6
Here is some C# code:
Process p = new Process();
p.StartInfo.FileName =
@"C:\temp\ConsoleApplication1\ConsoleApplication1\test1.bat";
// this doesn't work either:
//p.StartInfo.FileName = @"c:\windows\system32\cmd.exe";
//p.StartInfo.Arguments = @"/c
c:\temp\ConsoleApplication1\ConsoleApplication1\test1.bat";
p.Start();
p.WaitForExit();
Console.WriteLine("Exit code = {0}", p.ExitCode);
I would expect this program to print "Exit code = 6"...
But it actually prints "Exit code = 0".
Why?
Thanks in advance for your input!
Eva Pierce Monsen
having trouble getting Process.ExitCode to match up with what the .BAT
file returns.
Here are the contents of
C:\temp\ConsoleApplication1\ConsoleApplication1\test1.bat:
exit /B 6
Here is some C# code:
Process p = new Process();
p.StartInfo.FileName =
@"C:\temp\ConsoleApplication1\ConsoleApplication1\test1.bat";
// this doesn't work either:
//p.StartInfo.FileName = @"c:\windows\system32\cmd.exe";
//p.StartInfo.Arguments = @"/c
c:\temp\ConsoleApplication1\ConsoleApplication1\test1.bat";
p.Start();
p.WaitForExit();
Console.WriteLine("Exit code = {0}", p.ExitCode);
I would expect this program to print "Exit code = 6"...
But it actually prints "Exit code = 0".
Why?
Thanks in advance for your input!
Eva Pierce Monsen