本文整理汇总了TypeScript中cross-spawn类的典型用法代码示例。如果您正苦于以下问题:TypeScript cross-spawn类的具体用法?TypeScript cross-spawn怎么用?TypeScript cross-spawn使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了cross-spawn类的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: spawn
import * as spawn from 'cross-spawn';
import * as cp from 'child_process';
const p1: cp.ChildProcess = spawn('my-cmd', ['foo', 'bar']);
const pw: cp.ChildProcess = spawn('my-cmd', ['foo', 'bar'], {env: process.env});
pw.on('error', (err: Error) => {
console.log(err);
});
const r1: Error = spawn.sync('foo').error;
const r2: string[] = spawn.sync('foo').output;
const r3: Buffer = spawn.sync('foo').stdout;
const r4: Buffer = spawn.sync('foo').stderr;
const r5: number = spawn.sync('foo').status;
const r6: string = spawn.sync('foo').signal;
const r7: string = spawn.sync('foo', {encoding: 'utf8'}).stdout;
spawn.sync('foo', ['bar']);
spawn.sync('foo', ['bar'], {stdio: 'inherit'});
示例2: Promise
new Promise((resolve, reject) => {
const npm = spawn('npm', ['--prefix', cwd, 'install'], {
stdio: 'inherit',
});
npm.on('close', resolve);
npm.on('error', reject);
});
示例3: Promise
return new Promise((resolve, reject) => {
nreplProcess = spawn('lein', LEIN_ARGS, {
cwd: vscode.workspace.rootPath,
detached: !(os.platform() === 'win32')
});
nreplProcess.stdout.addListener('data', data => {
const nreplConnectionMatch = data.toString().match(R_NREPL_CONNECTION_INFO);
// Send any stdout messages to the output channel
nreplChannel.append(data.toString());
if (nreplConnectionMatch && nreplConnectionMatch[1]) {
const [host, port] = nreplConnectionMatch[1].split(':');
return resolve({ host, port: Number.parseInt(port) });
}
});
nreplProcess.stderr.on('data', data => {
// Send any stderr messages to the output channel
nreplChannel.append(data.toString());
});
nreplProcess.on('exit', (code) => {
// nREPL process has exited before we were able to read a host / port.
const message = `nREPL exited with code ${code}`
nreplChannel.appendLine(message);
// Bring the output channel to the foreground so that the user can
// use the output to debug the problem.
nreplChannel.show();
return reject({ nreplError: message});
});
});
示例4: Promise
return new Promise((resolve, reject) => {
const args = cmd.split(/\s/g)
const child = crossSpawn(args[0], args.slice(1), {
cwd: this.config.cwd,
})
child.stdout.on('data', data => {
this.out.log(data.toString())
})
child.stderr.on('data', data => {
this.out.log(data.toString())
})
child.on('error', err => {
this.out.error(err)
})
child.on('close', code => {
if (code !== 0) {
reject(code)
} else {
resolve()
}
})
})
示例5: Promise
return new Promise((resolve, reject) => {
let buffer = ''
const cp = crossSpawn(cmd, args, options)
cp.stdout.on('data', data => {
buffer += data.toString()
})
cp.stderr.on('data', data => {
buffer += data.toString()
})
cp.on('error', err => {
if (buffer.length > 0) {
reject(buffer)
} else {
reject(err)
}
})
cp.on('close', code => {
if (code === 0) {
resolve(buffer)
} else {
reject(buffer)
}
})
})