本文整理汇总了TypeScript中child_process.ChildProcess类的典型用法代码示例。如果您正苦于以下问题:TypeScript ChildProcess类的具体用法?TypeScript ChildProcess怎么用?TypeScript ChildProcess使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了ChildProcess类的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: Promise
return new Promise((resolve: Function, reject: Function): void => {
std.log('[TSC] compile => ' + path);
let childProcess: ChildProcess = spawn('tsc', [], path);
childProcess.stdout.on('data', (data: Buffer) => {
std.log('[TSC] ' + data.toString());
});
childProcess.stderr.on('error', (data: Buffer) => {
std.error('[TSC] ' + data.toString());
});
childProcess.on('error', reject);
childProcess.on('close', (code) => {
if (code !== 0) {
std.error(`[TSC] process exited with code ${code}`);
} else {
std.log('[TSC] Files compiled');
}
resolve();
});
});
示例2: resolve
return new Promise<string>((resolve, reject) => {
let childprocess: ChildProcess;
try {
childprocess = spawn('mono', ['--version'], { env: environment });
}
catch (e) {
return resolve(undefined);
}
childprocess.on('error', function (err: any) {
resolve(undefined);
});
let stdout = '';
childprocess.stdout.on('data', (data: NodeBuffer) => {
stdout += data.toString();
});
childprocess.stdout.on('close', () => {
let match = versionRegexp.exec(stdout);
if (match && match.length > 1) {
resolve(match[1]);
}
else {
resolve(undefined);
}
});
});
示例3: resolve
return new Promise<boolean>((resolve, reject) => {
let childprocess: ChildProcess;
try {
childprocess = spawn('mono', ['--version']);
}
catch (e) {
return resolve(false);
}
childprocess.on('error', function (err: any) {
resolve(false);
});
let stdout = '';
childprocess.stdout.on('data', (data: NodeBuffer) => {
stdout += data.toString();
});
childprocess.stdout.on('close', () => {
let match = versionRegexp.exec(stdout),
ret: boolean;
if (!match) {
ret = false;
}
else if (!range) {
ret = true;
}
else {
ret = satisfies(match[1], range);
}
resolve(ret);
});
});
示例4: spawn
return new Promise<any>((resolve: Function, reject: Function) => {
const chromeDriver = `${ROOT}\node_modules\protractor\selenium\chromedriver_2.21.exe`;
if(!Fs.existsSync(chromeDriver)){
let childProcess: ChildProcess = spawn("node", [PROTRACTOR_INSTALL, "update"]);
childProcess.stdout.on("data", (data) => {
std.log(data.toString());
});
childProcess.stderr.on("data", (data) => {
std.error('[INSTALL] '+data.toString());
});
childProcess.on("error", (data) => {
std.error('[INSTALL] '+data.toString());
});
childProcess.on('close', resolve);
} else {
resolve();
}
});
示例5: resolve
return new Promise<Success | Error>(resolve => {
const processProcessEnding = (code: number) => {
resolve({
success: true,
code,
stdout,
stderr
});
};
// If some error happens, then the "error" and "close" events happen.
// If the process ends, then the "exit" and "close" events happen.
// It is known that the order of events is not determined.
let processExited = false;
let processClosed = false;
process.on('error', (error: any) => {
outputChannel.appendLine(`error: error=${error}`);
resolve({ success: false });
});
process.on('close', (code, signal) => {
outputChannel.appendLine(`\nclose: code=${code}, signal=${signal}`);
processClosed = true;
if (processExited) {
processProcessEnding(code);
}
});
process.on('exit', (code, signal) => {
outputChannel.appendLine(`\nexit: code=${code}, signal=${signal}`);
processExited = true;
if (processClosed) {
processProcessEnding(code);
}
});
});
示例6: cb
runScript(script: string, cb: {(err: Error | null, res: any)}) {
const args = this.args.concat([script.trim()])
const scr = this.scr = spawn(this.command, args)
let output = {
stdout: '',
stderr: ''
}
scr.stdout.setEncoding('utf8')
scr.stderr.setEncoding('utf8')
scr.stdout.on('data', (d) => {
output.stdout += d
})
scr.stderr.on('data', (d) => {
output.stderr += d
})
scr.on('error', (err) => {
if (this.stopped) return
if (this.cbCalled) return
this.cbCalled = true
return cb(err, null)
})
scr.on('exit', (exitCode, signal) => {
if (this.stopped) return
if (this.cbCalled) return
this.cbCalled = true
if (exitCode !== 0) return cb(new Error(`script exited with non-zero exit code: ${exitCode} signal: ${signal}`), this.truncateOutput(output))
cb(null, this.truncateOutput(output))
})
}
示例7: onUpdateClick
function onUpdateClick() {
if (serverProcess != null) return;
refreshButton.disabled = true;
installOrUninstallButton.disabled = true;
updateButton.disabled = true;
const systemId = treeView.selectedNodes[0].dataset["systemId"];
const system = registry.systems[systemId];
serverProcess = forkServerProcess([ "update", systemId, "--force", `--download-url=${system.downloadURL}` ]);
progressLabel.textContent = `Running...`;
serverProcess.on("message", onOperationProgress);
serverProcess.on("exit", (statusCode: number) => {
serverProcess = null;
progressLabel.textContent = "";
if (statusCode === 0) {
system.localVersion = system.version;
updateSystemLabel(systemId);
}
refreshButton.disabled = false;
onSelectionChange();
});
}
示例8: runDiagnosticsWorker
function runDiagnosticsWorker(context: BuildContext) {
if (!diagnosticsWorker) {
const workerModule = path.join(__dirname, 'transpile-worker.js');
diagnosticsWorker = fork(workerModule, [], { env: { FORCE_COLOR: true } });
Logger.debug(`diagnosticsWorker created, pid: ${diagnosticsWorker.pid}`);
diagnosticsWorker.on('error', (err: any) => {
Logger.error(`diagnosticsWorker error, pid: ${diagnosticsWorker.pid}, error: ${err}`);
workerEvent.emit('DiagnosticsWorkerDone');
});
diagnosticsWorker.on('exit', (code: number) => {
Logger.debug(`diagnosticsWorker exited, pid: ${diagnosticsWorker.pid}`);
diagnosticsWorker = null;
});
diagnosticsWorker.on('message', (msg: TranspileWorkerMessage) => {
workerEvent.emit('DiagnosticsWorkerDone');
});
}
const msg: TranspileWorkerMessage = {
rootDir: context.rootDir,
buildDir: context.buildDir,
configFile: getTsConfigPath(context)
};
diagnosticsWorker.send(msg);
}
示例9: Promise
let childPromise = new Promise((resolve, reject) => {
child.on("error", e => result.error = e);
child.on("exit", (exit_code: number) => {
result.exit_code = exit_code;
resolve();
});
});
示例10: Observable
return new Observable((observer: Subscriber<Actions>) => {
spawn.on("error", error => {
// We both set the state and make it easy for us to log the error
observer.next(
actions.setExecutionState({
kernelStatus: "process errored",
kernelRef: action.payload.kernelRef
})
);
observer.error({ type: "ERROR", payload: error, err: true });
observer.complete();
});
spawn.on("exit", () => {
observer.next(
actions.setExecutionState({
kernelStatus: "process exited",
kernelRef: action.payload.kernelRef
})
);
observer.complete();
});
spawn.on("disconnect", () => {
observer.next(
actions.setExecutionState({
kernelStatus: "process disconnected",
kernelRef: action.payload.kernelRef
})
);
observer.complete();
});
});