pub const SpawnOptions = struct argv: []const []const u8cwd: Child.Cwd = .inheritSet to change the current working directory when spawning the child process.
environ_map: ?*const Environ.Map = nullReplaces the child environment when provided. The PATH value from here is not used to resolve argv[0]; that resolution always uses parent environment.
expand_arg0: ArgExpansion = .no_expandprogress_node: std.Progress.Node = std.Progress.Node.noneWhen populated, a pipe will be created for the child process to communicate progress back to the parent. The file descriptor of the write end of the pipe will be specified in the ZIG_PROGRESS environment variable inside the child process. The progress reported by the child will be attached to this progress node in the parent process.
The child's progress tree will be grafted into the parent's progress tree, by substituting this node with the child's root node.
stdin: StdIo = .inheritstdout: StdIo = .inheritstderr: StdIo = .inheritrequest_resource_usage_statistics: bool = falseSet to true to obtain rusage information for the child process. Depending on the target platform and implementation status, the requested statistics may or may not be available. If they are available, then the resource_usage_statistics field will be populated after calling wait. On Linux and Darwin, this obtains rusage statistics from wait4().
uid: ?posix.uid_t = nullSet to change the user id when spawning the child process.
gid: ?posix.gid_t = nullSet to change the group id when spawning the child process.
pgid: ?posix.pid_t = nullSet to change the process group id when spawning the child process.
start_suspended: bool = falseStart child process in suspended state. For Posix systems it's started as if SIGSTOP was sent.
create_no_window: bool = falseWindows-only. Sets the CREATE_NO_WINDOW flag in CreateProcess.
disable_aslr: bool = falseDarwin-only. Disable ASLR for the child process.
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444pub const SpawnOptions = struct {
argv: []const []const u8,
/// Set to change the current working directory when spawning the child process.
cwd: Child.Cwd = .inherit,
/// Replaces the child environment when provided. The PATH value from here
/// is not used to resolve `argv[0]`; that resolution always uses parent
/// environment.
environ_map: ?*const Environ.Map = null,
expand_arg0: ArgExpansion = .no_expand,
/// When populated, a pipe will be created for the child process to
/// communicate progress back to the parent. The file descriptor of the
/// write end of the pipe will be specified in the `ZIG_PROGRESS`
/// environment variable inside the child process. The progress reported by
/// the child will be attached to this progress node in the parent process.
///
/// The child's progress tree will be grafted into the parent's progress tree,
/// by substituting this node with the child's root node.
progress_node: std.Progress.Node = std.Progress.Node.none,
stdin: StdIo = .inherit,
stdout: StdIo = .inherit,
stderr: StdIo = .inherit,
/// Set to true to obtain rusage information for the child process.
/// Depending on the target platform and implementation status, the
/// requested statistics may or may not be available. If they are
/// available, then the `resource_usage_statistics` field will be populated
/// after calling `wait`.
/// On Linux and Darwin, this obtains rusage statistics from wait4().
request_resource_usage_statistics: bool = false,
/// Set to change the user id when spawning the child process.
uid: ?posix.uid_t = null,
/// Set to change the group id when spawning the child process.
gid: ?posix.gid_t = null,
/// Set to change the process group id when spawning the child process.
pgid: ?posix.pid_t = null,
/// Start child process in suspended state.
/// For Posix systems it's started as if SIGSTOP was sent.
start_suspended: bool = false,
/// Windows-only. Sets the CREATE_NO_WINDOW flag in CreateProcess.
create_no_window: bool = false,
/// Darwin-only. Disable ASLR for the child process.
disable_aslr: bool = false,
/// Behavior of the child process's standard input, output, and error streams.
pub const StdIo = union(enum) {
/// Inherit the corresponding stream from the parent process.
inherit,
/// Pass an already open file from the parent to the child.
///
/// Nonblocking mode will be kept in the child process if present. This is
/// likely not supported by the child process. For example:
/// - Zig's std.Io.File.stdout() assumes blocking mode
/// - Rust explicity documents that nonblocking stdio may cause panics
/// - C++ standard streams do not support nonblocking file descriptors
file: File,
/// Pass a null stream to the child process by opening "/dev/null" on POSIX
/// and "NUL" on Windows.
ignore,
/// Create a new pipe for the stream.
///
/// The corresponding field (`stdout`, `stderr`, or `stdin`) will be
/// assigned a `File` object that can be used to read from or write to the
/// pipe.
pipe,
/// Spawn the child process with the corresponding stream missing. This
/// will likely result in the child encountering EBADF if it tries to use
/// stdin, stdout, or stderr, or if only one stream is closed, it will
/// result in them getting mixed up. Generally, this option is for advanced
/// use cases only.
close,
};
}