Function runAllowFail [src]
Prototype
pub fn runAllowFail( b: *Build, argv: []const []const u8, out_code: *u8, stderr_behavior: std.process.Child.StdIo, ) RunError![]u8 Parameters
b: *Buildargv: []const []const u8out_code: *u8stderr_behavior: std.process.Child.StdIo Possible Errors
Windows-only. cwd was provided, but the path did not exist when spawning the child process.
Windows-only. NUL (U+0000), LF (U+000A), CR (U+000D) are not allowed
within arguments when executing a .bat/.cmd script.
- NUL/LF signifiies end of arguments, so anything afterwards would be lost after execution.
- CR is stripped by
cmd.exe, so any CR codepoints would be lost after execution.
WASI-only; file paths must be valid UTF-8.
Windows-only. cwd or argv was provided and it was invalid WTF-8.
https://simonsapin.github.io/wtf-8/
POSIX-only. StdIo.Ignore was selected and opening /dev/null returned ENODEV.
The Operating System returned an undocumented error code.
This error is in theory not possible, but it would be better to handle this error than to invoke undefined behavior.
When this error code is observed, it usually means the Zig Standard Library needs a small patch to add the error code to the error set for the respective function.
Source
pub fn runAllowFail(
b: *Build,
argv: []const []const u8,
out_code: *u8,
stderr_behavior: std.process.Child.StdIo,
) RunError![]u8 {
assert(argv.len != 0);
if (!process.can_spawn)
return error.ExecNotSupported;
const max_output_size = 400 * 1024;
var child = std.process.Child.init(argv, b.allocator);
child.stdin_behavior = .Ignore;
child.stdout_behavior = .Pipe;
child.stderr_behavior = stderr_behavior;
child.env_map = &b.graph.env_map;
try Step.handleVerbose2(b, null, child.env_map, argv);
try child.spawn();
var stdout_reader = child.stdout.?.readerStreaming(&.{});
const stdout = stdout_reader.interface.allocRemaining(b.allocator, .limited(max_output_size)) catch {
return error.ReadFailure;
};
errdefer b.allocator.free(stdout);
const term = try child.wait();
switch (term) {
.Exited => |code| {
if (code != 0) {
out_code.* = @as(u8, @truncate(code));
return error.ExitCodeFailure;
}
return stdout;
},
.Signal, .Stopped, .Unknown => |code| {
out_code.* = @as(u8, @truncate(code));
return error.ProcessTerminated;
},
}
}