ChildProcess (interface)
A class which represents a child process. The process may or may not be running.
This class is the API used internally by the exec function to spawn child processes.
Generally, you should not need to use the ChildProcess class directly, and
should use exec or $ instead. However, you may need to use it in some
special cases, like when specifying custom stdio for a process, or spawning a
non-blocking long-running process.
Example
child.start();
child.waitUntilComplete();
[key: string]: string;
};
stdio: {
};
| {
status: number;
signal: undefined;
}
| {
status: undefined;
signal: number;
};
}
ChildProcess.args (property)
The argv for the process. The first entry in this array is the program to run.
Example
ChildProcess.cwd (Path property)
The current working directory for the process.
Example
ChildProcess.env (object property)
The environment variables for the process.
Example
child.env.GREETING = "hello";
child.start();
child.waitUntilComplete();
[key: string]: string;
};
ChildProcess.stdio (object property)
The standard I/O streams for the process. Generally these are the same as
std.in, std.out, and std.err, but they can be customized to write
output elsewhere.
Example
child.stdio.out = logFile;
child.stdio.err = logFile;
child.start();
child.waitUntilComplete();
logFile.close();
ChildProcess.stdio.in (FILE property)
Where the process reads stdin from
Example
child.start();
child.waitUntilComplete();
ChildProcess.stdio.out (FILE property)
Where the process writes stdout to
Example
child.start();
child.waitUntilComplete();
ChildProcess.stdio.err (FILE property)
Where the process writes stderr to
Example
child.start();
child.waitUntilComplete();
ChildProcess.state (getter)
ChildProcess.pid (getter)
ChildProcess.start (method)
Spawns the process and returns its pid (process id).
Example
ChildProcess.waitUntilComplete (method)
Blocks the calling thread until the process exits or is killed.
Example
child.start();
const { status, signal } = child.waitUntilComplete();
status: number;
signal: undefined;
} | {
status: undefined;
signal: number;
};
ChildProcessState (type)
| {
id: "UNSTARTED";
}
| {
id: "STARTED";
}
| {
id: "STOPPED";
}
| {
id: "CONTINUED";
}
| {
id: "EXITED";
oldPid: number;
status: number;
}
| {
id: "SIGNALED";
oldPid: number;
signal: number;
};
ChildProcessOptions (type)
Options to be passed to the ChildProcess constructor. Their purposes and types match the same-named properties found on the resulting ChildProcess.
Example
cwd: "src",
};
ChildProcessOptions.cwd (property)
The current working directory for the process.
Example
child.start();
child.waitUntilComplete();
ChildProcessOptions.env (object property)
The environment variables for the process.
Example
});
child.start();
child.waitUntilComplete();
[key: string]: string;
};
ChildProcessOptions.stdio (object property)
The standard I/O streams for the process. Generally these are the same as
std.in, std.out, and std.err, but they can be customized to write
output elsewhere.
Example
stdio: { out: logFile, err: logFile },
});
child.start();
child.waitUntilComplete();
logFile.close();
ChildProcessOptions.stdio.in (FILE property)
Where the process reads stdin from
Example
});
child.start();
child.waitUntilComplete();
ChildProcessOptions.stdio.out (FILE property)
Where the process writes stdout to
Example
});
child.start();
child.waitUntilComplete();
ChildProcessOptions.stdio.err (FILE property)
Where the process writes stderr to
Example
});
child.start();
child.waitUntilComplete();
ChildProcessOptions.logging (object property)
Options which control logging
Example
});
ChildProcessOptions.logging.trace (function property)
Optional trace function which, if present, will be called at various times to provide information about the lifecycle of the process.
Defaults to the current value of logger.trace. logger.trace
defaults to a function which writes to stderr.
Example
});
child.start();
child.waitUntilComplete();
ChildProcessConstructor (interface)
new (
}
ChildProcessConstructor new(...) (construct signature)
Construct a new ChildProcess.
@paramargs — The argv for the process. The first entry in this array is the program to run.@paramoptions — Options for the process (cwd, env, stdio, etc)
Example
child.start();
child.waitUntilComplete();
new (args: string | Path | Array<string | number | Path>, options?: ChildProcessOptions): ChildProcess;
ChildProcessConstructor.prototype (readonly ChildProcess property)