Handling output in StartProcess RedirectedStandardOutputHandler in Cake.Build #4204
-
I want to call a custom tool with cake.build via
it works, but here some weirdness that I can't explain yet:
but the output ( Can anyone bring some light on this? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 2 replies
-
@DmitryLukyanov you need to share more of your code. Setting As I have written on SO (I have updated my answer), the So, given the following script: var target = Argument("target", "Default");
var settings = new ProcessSettings
{
Arguments = "/I task build.cake"
};
Task("NoRedirect")
.Does(() => {
Information("Running no redirect:");
var exitCode = StartProcess("findstr", settings);
Information("exited with code: " + exitCode);
});
Task("Redirect")
.Does(() => {
Information("Running redirect:");
settings.RedirectStandardOutput = true;
settings.RedirectedStandardOutputHandler = (x) => {
Information("--> " + x);
return x;
};
var exitCode = StartProcess("findstr", settings);
Information("exited with code: " + exitCode);
});
Task("Default")
.IsDependentOn("NoRedirect")
.IsDependentOn("Redirect");
RunTarget(target); Cake produces the following result:
|
Beta Was this translation helpful? Give feedback.
it's my mistake. The first output log is "omitted" because it doesn't exist. I used different search patterns: with and without file extension and this is why in one case I saw 2 lines output and in another - a single line.
Regarding the error code, apparently it's related to whether a command can find anything or no. If no - the error code will be 1, otherwise - 0