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

AccessDenied ExecveError
BadPathName ChangeCurDirError
CurrentWorkingDirectoryUnlinked SpawnError

Windows-only. cwd was provided, but the path did not exist when spawning the child process.

ExecNotSupported
ExitCodeFailure
FileBusy ExecveError
FileNotFound ExecveError
FileSystem ExecveError
InvalidBatchScriptArg SpawnError

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.
InvalidExe ExecveError
InvalidHandle GetProcessMemoryInfoError
InvalidName CreateProcessError
InvalidProcessGroupId SetPgidError
InvalidUserId SetEidError
InvalidUtf8 ChangeCurDirError

WASI-only; file paths must be valid UTF-8.

InvalidWtf8 SpawnError

Windows-only. cwd or argv was provided and it was invalid WTF-8. https://simonsapin.github.io/wtf-8/

IsDir ExecveError
NameTooLong ExecveError
NoDevice SpawnError

POSIX-only. StdIo.Ignore was selected and opening /dev/null returned ENODEV.

NotDir ExecveError
OutOfMemory SpawnError
PermissionDenied ExecveError
ProcessAlreadyExec SetPgidError
ProcessFdQuotaExceeded ExecveError
ProcessNotFound SetPgidError
ProcessTerminated
ReadFailure
ResourceLimitReached SetIdError
SymLinkLoop ChangeCurDirError
SystemFdQuotaExceeded ExecveError
SystemResources ExecveError
Unexpected UnexpectedError

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.

WaitAbandoned WaitForSingleObjectError
WaitTimeOut WaitForSingleObjectError

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(); const stdout = child.stdout.?.reader().readAllAlloc(b.allocator, 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; }, } }