module watt.process.spawn

Functions for starting a process.

Code Map

//! Functions for starting a process.
module watt.process.spawn;


//! Serves as a handle to a spawned process.
class Pid
{
public:
	alias OsHandle = pid_t;
	alias _pid = osHandle;
	alias NativeID = OsHandle;


public:
	osHandle: OsHandle;


public:
	this(osHandle: OsHandle) { }
	//! Wait for this process to finish, and get the return value.
	fn wait() i32 { }
}

//! Thrown if a process could not be spawned.
class ProcessException : Exception
{
public:
	this(msg: string) { }
}

//! Search the current working directory and PATH for the given command.
fn getCommandFromName(name: string) string { }
//! Start a process from the executable name and with the given args.
fn spawnProcess(name: string, args: string[]) Pid { }
//! Start a process from an executable.
fn spawnProcess(name: string, args: string[], inputStream: InputStdcStream, outputStream: OutputStdcStream, errorStream: OutputStdcStream, env: Environment) Pid { }
//! Start a process from an executable.
fn spawnProcess(name: string, args: string[], inputStream: InputFDStream, outputStream: OutputFDStream, errorStream: OutputFDStream, env: Environment) Pid { }
fn spawnProcess(name: string, args: string[], _stdin: FILE*, _stdout: FILE*, _stderr: FILE*, env: Environment) Pid { }
//! Search a PATH string for a command. If one is not given, PATH will be
//! retrieved and used.
fn searchPath(cmd: string, path: string) string { }
//! Get an environmental variable, or "" if it doesn't exist.
fn getEnv(env: string) string { }
//! Run a command through the libc system function.
fn system(name: string) i32 { }
fn spawnProcessPosix(name: string, args: string[], stdinFD: i32, stdoutFD: i32, stderrFD: i32, env: Environment) i32 { }
//! Wait for a specific process.
fn waitPosix(pid: pid_t) i32 { }
//! Wait for a process.
fn waitManyPosix(pid: pid_t) i32 { }
class Pid

Serves as a handle to a spawned process.

Usually you will not construct these, but will get them from spawnProcess.

fn wait() i32

Wait for this process to finish, and get the return value.

class ProcessException : Exception

Thrown if a process could not be spawned.

fn getCommandFromName(name: string) string

Search the current working directory and PATH for the given command.

fn spawnProcess(name: string, args: string[]) Pid

Start a process from the executable name and with the given args.

Example

pid := spawnProcess("volta", ["-c", "test.volt"]);
pid.wait();  // Blocks until the process is finished.
fn spawnProcess(name: string, args: string[], inputStream: InputStdcStream, outputStream: OutputStdcStream, errorStream: OutputStdcStream, env: Environment) Pid

Start a process from an executable.

Parameters

name
args
inputStream

Standard input will be read from this stream. If this is null, the system STDIN will be used.

outputStream

Standard output will be written to this stream. If this is null, the system STDOUT will be used.

errorStream

Standard error will be written to this stream. If this is null, the system STDERR will be used.

env

Return

A Pid instance for the new process.

Throws

  • ProcessException if a process could not be spawned for some reason.

fn searchPath(cmd: string, path: string) string

Search a PATH string for a command. If one is not given, PATH will be retrieved and used.

fn getEnv(env: string) string

Get an environmental variable, or "" if it doesn't exist.

fn system(name: string) i32

Run a command through the libc system function.

fn waitPosix(pid: pid_t) i32

Wait for a specific process.

fn waitManyPosix(pid: pid_t) i32

Wait for a process.