child_process#ChildProcessWithoutNullStreams TypeScript Examples
The following examples show how to use
child_process#ChildProcessWithoutNullStreams.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: utils.ts From airnode with MIT License | 7 votes |
killBackgroundProcess = (processToKill: ChildProcessWithoutNullStreams) => {
// We need to gracefully kill the Airnode docker otherwise it remains running on background
//
// The following reliably kills the Airnode process for unix, but it throws for windows.
// See: https://azimi.me/2014/12/31/kill-child_process-node-js.html
try {
process.kill(-processToKill.pid!);
} catch (e) {
// See: https://stackoverflow.com/a/28163919
spawn('taskkill', ['/pid', processToKill.pid!.toString(), '/f', '/t']);
}
}
Example #2
Source File: utils.ts From tesseract-server with MIT License | 7 votes |
waitForExitOrError = (
proc: ChildProcessWithoutNullStreams,
callback: (
err: Error | null | undefined,
data?: { code: number | null; signal: NodeJS.Signals | null },
) => void,
) => {
proc.once('error', err => {
callback(err);
});
proc.once('exit', (code, signal) => {
callback(undefined, { code, signal });
});
}
Example #3
Source File: buffer.ts From tesseract-server with MIT License | 6 votes |
bufferOutputs = (
proc: ChildProcessWithoutNullStreams,
callback: (
err: Error | undefined,
data?: { stderr?: Buffer; stdout?: Buffer },
) => void,
) => {
blStreams(
{
stderr: proc.stderr,
stdout: proc.stdout,
},
callback,
);
}
Example #4
Source File: do.ts From cli with Apache License 2.0 | 6 votes |
/**
* What to do when the condition is fulfilled
* @param callback the function to execute.
* It receives the process that fulfilled the condition
* (or the process owning the stream that fulfilled the condition).
* in parameter
* @returns a promise, extended with an 'until' function.
*/
private do(callback: DoCallback = () => {}) {
return (resolve: () => void) => {
const eventListener = this.addTerminalListener(
this.action.condition,
async (process: ChildProcessWithoutNullStreams) => {
await callback(process);
},
resolve
);
this.exitFunction = () => {
if (eventListener) {
this.removeListener(eventListener);
}
resolve();
};
};
}
Example #5
Source File: sapio.ts From sapio-studio with Mozilla Public License 2.0 | 6 votes |
export function start_sapio_oracle(): ChildProcessWithoutNullStreams | null {
if (g_emulator !== null) return g_emulator;
const oracle = preferences.data.local_oracle;
if (oracle !== 'Disabled' && 'Enabled' in oracle) {
const binary = preferences.data.sapio_cli.sapio_cli;
const seed = oracle.Enabled.file;
const iface = oracle.Enabled.interface;
const emulator = spawnSync(binary, ['emulator', 'server', seed, iface]);
if (emulator) {
let quit = '';
emulator.stderr.on('data', (data) => {
quit += `${data}`;
});
emulator.on('exit', (code) => {
if (quit !== '') {
console.error('Emulator Oracle Error', quit);
sys.exit();
}
});
emulator.stdout.on('data', (data) => {
g_emulator_log += `${data}`;
console.log(`stdout: ${data}`);
});
}
g_emulator = emulator;
return g_emulator;
}
return null;
}
Example #6
Source File: do.ts From cli with Apache License 2.0 | 6 votes |
/**
* Bound the `while.do` with an exit condition.
* If not specified (either with `until` or `once`) the hook will run till the process die.
* **It is highly recommended to specify one to ensure proper resource cleaning**
* @param untilCondition {Condition} a condition on which the hook chain (i.e. `where.do.until`) will unhook itself from the terminal.
* @returns {Promise} an awaitable promise that will resolve when the `untilCondition` is satisfied.
*/
public until(untilCondition: Condition): Promise<void> {
let eventListener: EventListenerObject | undefined;
return new Promise<void>((resolve) => {
eventListener = this.addTerminalListener(
untilCondition,
(_process: ChildProcessWithoutNullStreams, resolve: () => void) => {
this.exitFunction!();
resolve();
},
resolve
);
}).then(() => {
if (eventListener) {
this.removeListener(eventListener);
}
});
}
Example #7
Source File: startSMServer.ts From slice-machine with Apache License 2.0 | 6 votes |
export function startSMServer(
cwd: string,
port: string,
callback: (url: string) => void
) {
const smServer: ChildProcessWithoutNullStreams = spawn(
"node",
["../../server/src/index.js"],
{
cwd: __dirname,
env: {
...process.env,
CWD: cwd,
PORT: port,
},
}
);
smServer.stdout.on("data", function (data: Buffer) {
const lns = data.toString().split("Server running");
if (lns.length === 2) {
callback(lns[1].replace(/\\n/, "").trim());
} else {
console.log(data.toString());
}
});
smServer.stderr.on("data", function (data: Buffer) {
console.log("[slice-machine] " + data.toString());
});
}
Example #8
Source File: cli.ts From cli with Apache License 2.0 | 6 votes |
export function answerPrompt(answer: string) {
return (proc: ChildProcessWithoutNullStreams) =>
new Promise<void>((resolve) => {
if (!proc.stdin.write(answer)) {
proc.stdin.once('drain', () => resolve());
} else {
process.nextTick(() => resolve());
}
});
}
Example #9
Source File: processManager.ts From cli with Apache License 2.0 | 6 votes |
public spawn(
command: string,
args?: ReadonlyArray<string>,
options?: SpawnOptionsWithoutStdio
): ChildProcessWithoutNullStreams {
const process = nativeSpawn(command, args, {
detached: true,
...options,
});
process.on('exit', this.onExit(process));
this.processes.add(process);
return process;
}
Example #10
Source File: apps.ts From disco-cube-daemon with MIT License | 6 votes |
spawnApp = (name: string, command: string, args: string[]): RunningApp => {
const logger = log4js.getLogger(name);
logger.debug(`spawning app`, { name, command, args });
let proc: ChildProcessWithoutNullStreams | undefined = undefined;
try {
proc = spawn(command, args);
proc.stdout.on("data", (data) => {
logger.debug(`stdout: ${data}`);
});
proc.stderr.on("data", (data) => {
logger.error(`stderr: ${data}`);
});
proc.on("close", (code) => {
logger.debug(`child process exited with code ${code}`);
});
} catch (e) {
logger.error(`spawn error`, e);
}
return {
send: (data: any) => {
logger.warn(`cannot send data to a spawned app, must be forked.`);
},
stop: () => {
logger.debug(`stopping..`);
if (proc) kill(proc.pid);
},
};
}
Example #11
Source File: terminal.ts From cli with Apache License 2.0 | 5 votes |
private childProcess: ChildProcessWithoutNullStreams;
Example #12
Source File: Process.ts From tswow with GNU General Public License v3.0 | 5 votes |
processes : {[key: number]: ChildProcessWithoutNullStreams} = {}
Example #13
Source File: index.ts From tesseract-server with MIT License | 5 votes |
private readonly _proc: ChildProcessWithoutNullStreams;
Example #14
Source File: spawnWithWorkingDirectory.ts From tesseract-server with MIT License | 5 votes |
spawnWithWorkingDirectory = (
command: string,
args: readonly string[],
workingDirectory: string,
): ChildProcessWithoutNullStreams =>
ChildProcess.spawn(command, args, {
cwd: workingDirectory,
})
Example #15
Source File: client.ts From shadowsocks-electron with GNU General Public License v3.0 | 5 votes |
child: ChildProcessWithoutNullStreams | null
Example #16
Source File: spawn.ts From polkadot-launch with MIT License | 5 votes |
p: { [key: string]: ChildProcessWithoutNullStreams } = {}
Example #17
Source File: ffmpeg.ts From homebridge-eufy-security with Apache License 2.0 | 5 votes |
private readonly process: ChildProcessWithoutNullStreams;
Example #18
Source File: sapio.ts From sapio-studio with Mozilla Public License 2.0 | 5 votes |
g_emulator: null | ChildProcessWithoutNullStreams = null
Example #19
Source File: Process.ts From tswow with GNU General Public License v3.0 | 5 votes |
private _process: ChildProcessWithoutNullStreams | undefined;
Example #20
Source File: index.ts From bluebubbles-server with Apache License 2.0 | 5 votes |
childProc: ChildProcessWithoutNullStreams;
Example #21
Source File: orchestrator.ts From cli with Apache License 2.0 | 5 votes |
public constructor(public process: ChildProcessWithoutNullStreams) {
this.actions = new Array<Action>();
}
Example #22
Source File: do.ts From cli with Apache License 2.0 | 5 votes |
private addTerminalListener(
condition: Condition,
callback: (
process: ChildProcessWithoutNullStreams,
resolve: () => void
) => void,
resolve: () => void
) {
const target: Readable | ChildProcessWithoutNullStreams = this.getTarget();
let onParams: [string, (data: Buffer) => void] | undefined;
if (isConditionRegExp(condition)) {
onParams = [
'data',
(data: Buffer) => {
if (condition.test(stripAnsi(data.toString()).replace(/\n/g, ''))) {
callback(this.action.process, resolve);
}
},
];
}
if (isConditionString(condition)) {
onParams = [condition, () => callback(this.action.process, resolve)];
}
if (isConditionPromise(condition)) {
condition.then(() => callback(this.action.process, resolve));
return;
}
if (onParams) {
target.on(...onParams);
return {target, event: onParams[0], listener: onParams[1]};
}
throw new Error(
`Terminal Action malformed:\n${JSON.stringify(this.action)}`
);
}
Example #23
Source File: do.ts From cli with Apache License 2.0 | 5 votes |
private getTarget(): Readable | ChildProcessWithoutNullStreams {
return this.action.target === 'process'
? this.action.process
: this.action.process[this.action.target];
}
Example #24
Source File: action.ts From cli with Apache License 2.0 | 5 votes |
public constructor(public process: ChildProcessWithoutNullStreams) {}
Example #25
Source File: processManager.ts From cli with Apache License 2.0 | 5 votes |
private onExit = (process: ChildProcessWithoutNullStreams) => () => {
this.processes.delete(process);
};
Example #26
Source File: processManager.ts From cli with Apache License 2.0 | 5 votes |
private processes: Set<ChildProcessWithoutNullStreams>;
Example #27
Source File: processManager.ts From cli with Apache License 2.0 | 5 votes |
public constructor() {
this.processes = new Set<ChildProcessWithoutNullStreams>();
}
Example #28
Source File: plugin_jsonrpc_stdio.ts From omegga with ISC License | 5 votes |
#child: ChildProcessWithoutNullStreams;
Example #29
Source File: server.ts From omegga with ISC License | 5 votes |
#child: ChildProcessWithoutNullStreams = null;