2

I am running a WebDeploy package deployment command ([myapp].deploy.cmd) using the following code:

Process process = new Process();
process.StartInfo.FileName = FileName;
process.StartInfo.Arguments = Args;
process.StartInfo.UseShellExecute = false;
process.StartInfo.RedirectStandardOutput = true;
process.StartInfo.RedirectStandardError = true;
process.StartInfo.CreateNoWindow = true;
process.EnableRaisingEvents = true;
process.Start();
process.BeginOutputReadLine();
process.BeginErrorReadLine();
process.ErrorDataReceived += DataReceived;
process.OutputDataReceived += DataReceived;
process.WaitForExit();
return process.ExitCode;

it always returns an exit code of 0 even when the command fails. I have running the command directly from the command line with the same arguments and it does exit with code 1 (echo %ERRORLEVEL%) so I there must be something in the way I am starting the process that means this is not caught by the Process instance?

Myles McDonnell
  • 12,943
  • 17
  • 66
  • 116
  • How does deploy.cmd set the return value? Could it be related to this issue? http://stackoverflow.com/questions/13248274/exitcode-is-always-0-when-executing-a-bat-file – Heinzi Dec 03 '15 at 16:59
  • You mean how does deploy set the exit code? Yes, I have a hunch that may be the issue as if I run a simple batch file that just calls 'exit 1' I get the expected behaviour. I find that hard to reason though as echo %ERRORLEVEL% returns 1 after I run the cmd direct (not using a .net app) – Myles McDonnell Dec 03 '15 at 17:02
  • Turns out it was something to do with the cmd so I now call msdeploy directly rather than via the cmd and it's all good. – Myles McDonnell Dec 03 '15 at 17:51

0 Answers0