我正在使用以下代码运行WebDeploy包部署命令([myapp] .deploy.cmd):
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;
即使命令失败,它也始终返回退出代码0。我直接从命令行运行命令并使用相同的参数,它确实退出代码1(echo%ERRORLEVEL%)所以我必须有一些东西在我启动进程的方式,这意味着这不会被进程捕获实例