C# 如何基于退出代码执行任意可执行和失败的蛋糕构建?
如何在Cake build脚本中运行任意可执行文件并检查该程序的退出代码?C# 如何基于退出代码执行任意可执行和失败的蛋糕构建?,c#,process,cakebuild,C#,Process,Cakebuild,如何在Cake build脚本中运行任意可执行文件并检查该程序的退出代码? 如果它没有返回给定的退出代码,那么我希望构建失败。这是使用别名实现的 例如: int pingLocalResult = StartProcess("ping", "-n 1 127.0.0.1"); if (pingLocalResult != 0) { throw new Exception("Ping 127.0.0.1 failed."); } int pingZeroResult = StartPr
如果它没有返回给定的退出代码,那么我希望构建失败。这是使用别名实现的 例如:
int pingLocalResult = StartProcess("ping", "-n 1 127.0.0.1");
if (pingLocalResult != 0)
{
throw new Exception("Ping 127.0.0.1 failed.");
}
int pingZeroResult = StartProcess("ping", "-n 1 0");
if (pingZeroResult != 0)
{
throw new Exception("Ping 0 failed.");
}
将输出如下内容:
C:\> cake .\startprocess.cake
Pinging 127.0.0.1 with 32 bytes of data:
Reply from 127.0.0.1: bytes=32 time<1ms TTL=128
Ping statistics for 127.0.0.1:
Packets: Sent = 1, Received = 1, Lost = 0 (0% loss),
Approximate round trip times in milli-seconds:
Minimum = 0ms, Maximum = 0ms, Average = 0ms
Pinging 0.0.0.0 with 32 bytes of data:
PING: transmit failed. General failure.
Ping statistics for 0.0.0.0:
Packets: Sent = 1, Received = 0, Lost = 1 (100% loss),
Error: Ping 0 failed.
C:\>
C:\>cake。\startprocess.cake
使用32字节数据ping 127.0.0.1:
127.0.0.1回复:字节=32次
其中,抛出新异常(“Ping 0失败”)代码>将中断/中止生成