How to use the exec function from child_process
Find comprehensive JavaScript child_process.exec code examples handpicked from public code repositorys.
35 36 37 38 39 40 41 42 43 44
await mkdir(path.join(destination, folder)); console.log(`Successfully created folder: ${folder}`); // Generate component process.chdir(path.join(destination, folder)); exec( `ng generate component ${componentName}-${exampleName}-example --skip-import --skip-tests=true --type= --prefix= --flat`, (err, stdout, stderr) => { if (err) { console.error(err);
30
195
0
GitHub: zotero/zotero
54 55 56 57 58 59 60 61 62 63
const buildDirPath = path.join(ROOT, 'build'); const wrappedPaths = relPaths.map(relPath => `"${path.relative(buildDirPath, relPath)}"`); await new Promise((resolve, reject) => { const cmd = `"${addOmniExecPath}" ${wrappedPaths.join(' ')}`; exec(cmd, { cwd: buildDirPath }, (error, output) => { if (error) { reject(error); } else {
601
0
121
238 239 240 241 242 243 244 245 246 247
}; /** * 执行某一个cli命令,如果执行失败就提升为sudo权限 */ exports.runCommand = function(command, callback) { return child_process.exec(command, function(error, stdout, stderr) { if (_.any([exports.isPermissionError(error), exports.isPermissionError(new Error(stderr))])) { return president.execute(command, callback); } return callback(error, stdout, stderr);
106
801
61
+ 3 other calls in file
38 39 40 41 42 43 44 45 46 47
function runNgc(tsConfigPath) { console.log('Started for', tsConfigPath); const ngc = path.resolve('node_modules', '.bin', 'ngc'); return new Promise((resolve, reject) => { exec(`${ngc} -p ${tsConfigPath}`, (err, stdout, stdeer) => { if (err) { console.log('Error !', err); reject(err); }
122
286
0
453 454 455 456 457 458 459 460 461 462
} else { console.log('Setup js-controller...'); let __pid; if (debug) { // start controller child_process.exec('node ' + appName + '.js setup first', { cwd: rootDir + 'tmp/node_modules/' + appName + '.js-controller', stdio: [0, 1, 2] }); } else {
48
117
29
+ 7 other calls in file
GitHub: lamassu/lamassu-machine
1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144
this._setupWebcam() this._setupCheckPower() } Brain.prototype.setupSsuboard = function setupSsuboard () { cp.exec('ntpq -c "host time.nist.gov"', {}, err => { if (err) console.log(err) }) }
129
95
17
+ 3 other calls in file
GitHub: inovua/reactdatagrid
5 6 7 8 9 10 11 12 13
*/ const path = require('path'); const fs = require('fs'); const childProcess = require('child_process'); const exec = childProcess.exec; const execSync = childProcess.execSync; const buildStyle = require('./buildStyle'); const mkdirp = require('mkdirp');
45
0
18
GitHub: appblocks-hub/BB-CLI
74 75 76 77 78 79 80 81 82 83 84
return { metaData, isRegistered } } function pexec(cmd) { return new Promise((resolve) => { exec(cmd, {}, (error, stdout, stderr) => { if (error) { resolve({ status: 'error', msg: stdout.toString() || stderr.toString() }) } resolve({ status: 'success', msg: stdout.toString() || stderr.toString() })
4
9
2
+ 2 other calls in file
250 251 252 253 254 255 256 257 258 259 260 261
done(); }); gulp.task('clean', function (done) { const command = 'rm -rf ' + PRODUCTION_SITE_BASE; childProcess.exec(command); done(); }); gulp.task('default',
4
7
5
+ 14 other calls in file
GitHub: ahlulmukh/AbotMD
3197 3198 3199 3200 3201 3202 3203 3204 3205 3206
); reply(mess.wait); var media = fs.readFileSync(`./sticker/${sender.split("@")[0]}.mp4`); let ran = "./sticker/" + getRandom(".mp3"); fs.writeFileSync(`./${ran}`, media); exec(`ffmpeg -i ${media} ${ran}`); conn.sendMessage( from, { audio: fs.readFileSync(ran),
2
3
1
+ 3 other calls in file
GitHub: progovoy/vmn-action
6 7 8 9 10 11 12 13 14 15 16 17
const getCurrentBranchName = require('node-git-current-branch'); let out; const execute = (command, skip_error=false) => new Promise((resolve, reject) => { childProcess.exec(command, (error, stdout, stderr) => { if ((error || stderr) && !skip_error) { reject(stderr); return; }
1
13
3
15 16 17 18 19 20 21 22 23 24
checkJava = function (java) { return new Promise(resolve => { if (java == void 0) return resolve({ run: false }); let cmd = `"${java}" -version`; child.exec(cmd, {}, (error, stdout, stderr) => { if (error) { resolve({ run: false, message: error }); } else { resolve({ run: true, version: stderr.match(/"(.*?)"/).pop(), arch: stderr.includes('64-Bit') ? '64-Bit' : '32-Bit' });
0
2
1
228 229 230 231 232 233 234 235 236 237
if(userIsCreated && !authResult){ return res.status(404).send("Error: Route protected") } exec('cat master', { cwd: '/home/revo/' }, (err, stdout, stderr) => { if (err) { res.status(404).send(err); } else { res.send(stdout);
0
1
1
+ 39 other calls in file
41 42 43 44 45 46 47 48 49 50 51
])}`; }; module.exports.executeCommand = async function (cmd) { return new Promise((resolve, reject) => { exec(cmd, (err, stdout, stderr) => { if (err) { reject(err); return; }
46
212
9
+ 2 other calls in file
GitHub: Wandygans/basebaru1
562 563 564 565 566 567 568 569 570 571
let cp = require('child_process') let { promisify } = require('util') let exec = promisify(cp.exec).bind(cp) let o try { o = await exec(command.trimStart() + ' ' + text.trimEnd()) } catch (e) { o = e } finally { let { stdout, stderr } = o
0
1
1
28 29 30 31 32 33 34 35 36 37
} if (!citel.quoted) return citel.reply('_Need Media._') let mime = citel.quoted.mtype let media = await Void.downloadAndSaveMediaMessage(citel.quoted); let name = await getRandom('.png') exec(`ffmpeg -i ${media} ${name}`, (err) => { let buffer = fs.readFileSync(ran) Void.sendMessage(citel.chat, { image: buffer }, { quoted: citel }) }) fs.unlinkSync(media)
0
0
1
+ 2 other calls in file
GitHub: TAKIO716/LINXZ-BOTZ
247 248 249 250 251 252 253 254 255 256
}; download(url, './database/stick' + names + '.png', async function () { console.log('selesai'); let filess = './database/stick' + names + '.png' let asw = './database/stick' + names + '.webp' exec(`ffmpeg -i ${filess} -vcodec libwebp -filter:v fps=fps=20 -lossless 1 -loop 0 -preset default -an -vsync 0 -s 512:512 ${asw}`, (err) => { let media = fs.readFileSync(asw) naze.sendMessage(to, { sticker: media}, {quoted: m}) fs.unlinkSync(filess) fs.unlinkSync(asw)
0
0
1
+ 4 other calls in file
GitHub: webconsistLab/api
249 250 251 252 253 254 255 256 257 258 259
}); ipcMain.on('open_link', (event, arg) => { var url = arg; exec('start chrome --new-window '+url+'', (err) => { if (err) { console.error(`Error executing command: ${err}`); } });
0
0
0
+ 2 other calls in file
237 238 239 240 241 242 243 244 245 246
function runExtractCmd() { const { exec } = require("child_process"); exec("yarn node ./Dist/extract " + source + " " + dest, (error, stdout, stderr) => { if (error) { blip.server.loggerErr(error + ', Extracting ' + paramsSD.logDesc + ' file: ' + source); return callback(true);
0
0
1
+ 4 other calls in file
46 47 48 49 50 51 52 53 54 55 56
} }); } function shutdown() { exec(`shutdown -s -t 0`, (err, stdout, stderr) => { if (err) { console.error(err); return; }
0
0
1
+ 14 other calls in file
child_process.execSync is the most popular function in child_process (240 examples)