本文整理汇总了TypeScript中child-process-promise.spawn函数的典型用法代码示例。如果您正苦于以下问题:TypeScript spawn函数的具体用法?TypeScript spawn怎么用?TypeScript spawn使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了spawn函数的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: Error
}, (progress) => {
const coursierPromise =
cpp.spawn("java", [
"-jar", coursierPath,
"fetch",
"-p",
artifact
])
const coursierProc = coursierPromise.childProcess
let classPath = ""
coursierProc.stdout.on('data', (data: Buffer) => {
classPath += data.toString().trim()
})
coursierProc.stderr.on('data', (data: Buffer) => {
let msg = data.toString()
outputChannel.append(msg)
})
coursierProc.on('close', (code: number) => {
if (code != 0) {
let msg = "Fetching the language server failed."
outputChannel.append(msg)
throw new Error(msg)
}
run({
command: "java",
args: ["-classpath", classPath, "dotty.tools.languageserver.Main", "-stdio"]
})
})
return coursierPromise
})
示例2: execAsync
static async execAsync(command: string, args: Array<string>, workDir = null): Promise<void> {
Guard.argumentNotNullOrEmpty(command, "command");
Guard.argumentNotNull(args, "args");
let cwd = process.cwd();
if (workDir) {
if (!path.isAbsolute(workDir)) {
workDir = path.join(cwd, workDir);
}
if (!fs.existsSync(workDir)) {
throw new Error(`Can't find ${workDir}.`);
}
process.chdir(workDir);
}
let promise = cp.spawn(command, args);
let childProcess = promise.childProcess;
childProcess.stdout.on("data", (data) => {
process.stdout.write(data.toString());
});
childProcess.stderr.on("data", (data) => {
process.stderr.write(data.toString());
})
return promise.then(() => {
process.chdir(cwd);
});
}
示例3: runBuildTask
async function runBuildTask({ pkgName, cmd, args, env = {} }: BuildTaskArgs) {
const promise = spawn(cmd, args, {
cwd: path.join(__dirname, '..'),
env: {
...process.env,
...env
}
});
const { childProcess } = promise;
childProcess.stdout.on('data', data => {
stdout.write(data);
});
childProcess.stderr.on('data', data => {
stderr.write(data);
});
childProcess.on('close', code => {
if (code) {
stderr.write(error(`${chalk.bold(pkgName)}\n`));
} else {
stdout.write(done(`${chalk.bold(pkgName)}\n`));
}
});
return promise;
}
示例4: Error
}, (progress) => {
const args = [
"-jar", coursierPath,
"fetch",
"-p",
artifact
].concat(extra)
const coursierPromise = cpp.spawn("java", args)
const coursierProc = coursierPromise.childProcess
let classPath = ""
coursierProc.stdout.on('data', (data: Buffer) => {
classPath += data.toString().trim()
})
coursierProc.stderr.on('data', (data: Buffer) => {
let msg = data.toString().trim()
outputChannel.appendLine(msg)
})
coursierProc.on('close', (code: number) => {
if (code != 0) {
let msg = `Couldn't fetch '${ artifact }' (exit code ${ code }).`
outputChannel.appendLine(msg)
throw new Error(msg)
}
})
return coursierPromise.then(() => { return classPath })
})
示例5: build
build() {
return spawn('node', [
`${path.resolve(__dirname, 'child_proc.js')}`,
`--sourceHtml=${path.resolve(this.inputPaths[0], this.indexPath)}`,
`--optionsPath=${path.resolve(this.inputPaths[0], this.appShellPath)}`,
`--outputIndexPath=${path.resolve(this.outputPath, this.indexPath)}`
]);
}