Function waitForSpawn [src]

On some targets, spawn may not report all spawn errors, such as error.InvalidExe. This function will block until any spawn errors can be reported, and return them.

Prototype

pub fn waitForSpawn(self: *ChildProcess) SpawnError!void

Parameters

self: *ChildProcess

Possible Errors

AccessDenied ExecveError
BadPathName ChangeCurDirError
CurrentWorkingDirectoryUnlinked

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

FileBusy ExecveError
FileNotFound ExecveError
FileSystem ExecveError
InvalidBatchScriptArg

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

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

IsDir ExecveError
NameTooLong ExecveError
NoDevice

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

NotDir ExecveError
OutOfMemory
PermissionDenied ExecveError
ProcessAlreadyExec SetPgidError
ProcessFdQuotaExceeded ExecveError
ProcessNotFound SetPgidError
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 waitForSpawn(self: *ChildProcess) SpawnError!void { if (native_os == .windows) return; // `spawn` reports everything if (self.term) |term| { _ = term catch |spawn_err| return spawn_err; return; } const err_pipe = self.err_pipe orelse return; self.err_pipe = null; // Wait for the child to report any errors in or before `execvpe`. if (readIntFd(err_pipe)) |child_err_int| { posix.close(err_pipe); const child_err: SpawnError = @errorCast(@errorFromInt(child_err_int)); self.term = child_err; return child_err; } else |_| { // Write end closed by CLOEXEC at the time of the `execvpe` call, indicating success! posix.close(err_pipe); } }