本文整理汇总了TypeScript中child_process.exec函数的典型用法代码示例。如果您正苦于以下问题:TypeScript exec函数的具体用法?TypeScript exec怎么用?TypeScript exec使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了exec函数的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: Promise
return new Promise((resolve): void => {
exec("yarn --network-concurrency 1", {
cwd: path,
maxBuffer: 1024 * 1024 * 10,
}, (error, stdout, stderr) => {
if (error) {
logger.error(
`Failed to install "${pkg}" dependencies`,
field("error", error),
field("stdout", stdout),
field("stderr", stderr),
);
process.exit(1);
}
logger.info(`Successfully grabbed \"${pkg}\" dependencies!`);
resolve();
});
});
示例2: exportPDF
function exportPDF(req: express.Request, res: express.Response) {
let phantomBin = 'phantomjs', dest = 'data.' + req.query.format, file = utils.guid() + '.pdf';
const exec = require('child_process').exec;
if (os.platform().substr(0, 3) == 'win') {
phantomBin = '"../node_modules/gator-web/bin/phantomjs-win"'
}
let reportUrl = application.current.consoleHost;
if (utils.config.dev())
reportUrl = application.settings.nodeUrl;
reportUrl += '/report?format=pdf&accessToken=' + req['session'].accessToken + '&options=' + encodeURIComponent(req.query.options);
const child = exec('cd phantomjs && ' + phantomBin + ' --ignore-ssl-errors=yes ../node_modules/gator-web/lib/renderpdf.js "' + reportUrl + '" ' + file,
(err, stdout, stderr) => {
if (err !== null) {
api.log(err, "PDF download");
res.end("Internal error");
} else {
res.download('phantomjs/' + file, 'report.pdf', function(err) {
try {
if (err){
api.log(err, "PDF download");
res.end("Internal error");
} else {
let stat = fs.statSync('phantomjs/' + file);
if (stat.isFile())
fs.unlink('phantomjs/' + file);
}
} catch(err) {}
});
}
}
);
}
示例3: exec
return new Promise<any>((resolve, reject) => {
let cmd = [command].concat(args).join(' ');
this.ui.info(`Running command \`${cmd}\``);
let child = exec(cmd, options);
child.stdout.on('data', (data: string) => {
this.ui.log(data, this.ui.LOG_LEVEL.INFO);
});
child.stderr.on('data', (data: string) => {
this.ui.error(data);
});
child.on('close', (code: string) => {
this.ui.debug(`${command} exited with code ${code}`);
resolve();
});
});
示例4: exec
rawEncodingPromise = new TPromise<string>(c => {
if (verbose) {
console.log('Running "chcp" to detect terminal encoding...');
}
exec('chcp', (err, stdout, stderr) => {
if (stdout) {
const windowsTerminalEncodingKeys = Object.keys(windowsTerminalEncodings);
for (let i = 0; i < windowsTerminalEncodingKeys.length; i++) {
const key = windowsTerminalEncodingKeys[i];
if (stdout.indexOf(key) >= 0) {
return c(windowsTerminalEncodings[key]);
}
}
}
return c(void 0);
});
});
示例5: it
it("reviewjs build でRuby用設定ファイルを元にファイル群のコンパイルができること", () => {
let baseDir = "test/fixture/ruby-book/";
/* tslint:disable:no-require-imports */
let fs = require("fs");
/* tslint:enable:no-require-imports */
if (fs.existsSync(baseDir + "ch01.html")) {
fs.unlinkSync(baseDir + "ch01.html");
}
if (fs.existsSync(baseDir + "ch02.html")) {
fs.unlinkSync(baseDir + "ch02.html");
}
assert(!fs.existsSync(baseDir + "ch01.html"));
assert(!fs.existsSync(baseDir + "ch02.html"));
return exec("../../../bin/reviewjs build", { cwd: baseDir })
.then(() => {
assert(fs.existsSync(baseDir + "ch01.html"));
assert(fs.existsSync(baseDir + "ch02.html"));
});
});
示例6: exec
return new Promise<string>((resolve, reject) => {
console.log(`>> ${command}`);
exec(command, {
encoding: "utf8",
maxBuffer: 1024 * 1024,
}, (error, stdout, stderr) => {
if (stdout.length > 0) {
console.log(stdout);
}
if (stderr.length > 0) {
console.error(stderr);
}
if (error) {
reject(error);
} else {
resolve(stdout);
}
});
});
示例7: executeCordovaCommand
export function executeCordovaCommand(cwd: string, command: string): Q.Promise<any> {
let deferred = Q.defer<any>();
let cordovaCmd = os.platform() === "darwin" ? "cordova" : "cordova.cmd";
let commandToExecute = cordovaCmd + " " + command;
let process = child_process.exec(commandToExecute, { cwd: cwd });
process.on("error", function (err: any): void {
deferred.reject(err);
});
process.stdout.on("close", exitCode => {
if (exitCode) {
deferred.reject("Cordova command failed with exit code " + exitCode);
} else {
deferred.resolve({});
}
});
return deferred.promise;
}
示例8: stop
export function stop(){
let stopped: boolean = false;
if (processes.run.get_status()){
processes.run.stop();
stopped = true;
}
if (processes.build.get_status()){
processes.build.stop();
stopped = true;
}
if (processes.syntax.get_status()){
processes.syntax.stop();
stopped = true;
}
if (!stopped){
console.log('make -C '+paths.Bela+' stop');
child_process.exec('make -C '+paths.Bela+' stop');
}
}
示例9: openUrl
function openUrl(startUrl: string) {
if (!/^[a-z0-9A-Z#=\.\-\\\/%:\?_]+$/.test(startUrl)) {
console.error("invalid URL to open: " + startUrl)
return
}
let cmds: U.Map<string> = {
darwin: "open",
win32: "start",
linux: "xdg-open"
}
if (/^win/.test(os.platform()) && !/^[a-z0-9]+:\/\//i.test(startUrl))
startUrl = startUrl.replace('/', '\\');
else
startUrl = startUrl.replace('\\', '/');
let cmd = cmds[process.platform];
console.log(`opening ${startUrl}`)
child_process.exec(`${cmd} ${startUrl}`);
}
示例10: callback
(pageCount, callback) => {
let output = BURST_FOLDER + duid.getDUID(1)[0] + '_page_%02d.pdf';
mkdirp.sync(BURST_FOLDER); //this folder is periodically removed
let command = OS_BATCH_RUN_PREFIX + ' pdftk ' + filepath + ' burst output ' + output;
logging.info('Running external command: ' + command);
child_process.exec(command, (err, stdout, stderr)=> {
if (err)
return callback(err || stderr);
let files = [];
let i = 1;
while (i <= pageCount) {
let no = ('0' + (i++).toString()).slice(-2);
files.push(output.replace('%02d', no));
}
callback(null, files);
});
}], final_callback);