How to use the child_process.exec function in child_process

To help you get started, we’ve selected a few child_process examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github ioBroker / ioBroker.simple-api / test / lib / setup.js View on Github external
setTimeout(function () {
                client.destroy();
                if (!fs.existsSync(rootDir + 'tmp/node_modules/' + appName + '.js-controller')) {
                    console.log('installJsController: no js-controller => install from git');

                    child_process.execSync('npm install https://github.com/' + appName + '/' + appName + '.js-controller/tarball/master --prefix ./  --production', {
                        cwd:   rootDir + 'tmp/',
                        stdio: [0, 1, 2]
                    });
                } 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 {
                        child_process.fork(appName + '.js', ['setup', 'first'], {
                            cwd:   rootDir + 'tmp/node_modules/' + appName + '.js-controller',
                            stdio: [0, 1, 2, 'ipc']
                        });
                    }
                }

                // let npm install admin and run setup
                checkIsControllerInstalled(function () {
                    let _pid;

                    if (fs.existsSync(rootDir + 'node_modules/' + appName + '.js-controller/' + appName + '.js')) {
github hypery2k / nativescript-fabric / src / scripts / build-native.js View on Github external
const { exec } = require('child_process');
const semver = require('semver');

const currentDir = process.cwd();

exec('tns --version', (err, stdout, stderr) => {
  if (err) {
    // node couldn't execute the command
    console.log(`tns --version err: ${err}`);
    return;
  }

  const tnsVersion = semver.major(stdout);

  // execute 'tns plugin build' for {N} version > 4. This command builds .aar in platforms/android folder.
  if (tnsVersion >= 4) {
    console.log(`executing 'tns plugin build' in ${currentDir}`);
    exec(`cd ${currentDir} && tns plugin build`);
  }
});
github makotogo / developerWorks / makoto-home-automation / nodejs / homeAutomationController.js View on Github external
function applyIotDeviceAction(actionMetadata) {
    // Execute the codesend program and pass it the arguments it needs
    var encoding = actionMetadata.encoding;
    var delay = actionMetadata.delay;

    // Build the transmit command that sends the signal to the
    /// 433MHz IoT device
    var transmitCommand = appConfig.transmitterProgram + " " + encoding + " " + delay;
    winston.debug("Sending command to device: " + transmitCommand);
    // Now execute the transmit command
    exec(transmitCommand, function (error, stdout, stderr) {
        winston.info("stdout: " + stdout);
        winston.info('stderr: ' + stderr);
        if (error) {
            winston.error("Error while invoking command '" + transmitCommand + ": " + error.message.toString());
        }
    });

}
github sailshq / treeline1 / legacy / lib / syncMachines.js View on Github external
// Output the package.json for this pack
          packageJsonStr = beautify(JSON.stringify(newPackageJson), {indent_size: 2});
          if (packageJsonStr == beautify(JSON.stringify(packageJson), {indent_size: 2})) {
            return nextPack();
          }


          fs.writeFileSync(path.join(machinesDir, machineDir, 'package.json'), packageJsonStr);

          // Write out the index file
          fs.writeFileSync(path.join(machinesDir, machineDir, 'index.js'), "module.exports = require('machine').pack({pkg: require('./package.json'), dir: __dirname});");

          // If there are dependencies, run npm install
          if(_.keys(newPackageJson.dependencies).length) {
            var cwd = path.join(machinesDir, machineDir);
            exec('npm install', {cwd: cwd}, function(err, stdout) {
              if (err) {return nextPack(err);}
              nextPack();
            });
          }

          // Otherwise we don't need to install anything
          else {
            return nextPack();
          }


        }
      }, cb);
github bang-olufsen / create / Beocreate2 / beo-extensions / snapcast / index.js View on Github external
} else {
					if (configuration[options[i].option]) {
						if (options[i].remove) {
							if (debug) console.log("Configuring Snapcast (removing "+options[i].option+")...")
							delete configuration[options[i].option];
						} else {
							if (debug) console.log("Configuring Snapcast (commenting out "+options[i].option+")...")
							configuration[options[i].option].comment = true;
						}
					}
				}
			}
		}
		writeSnapcastConfiguration();
		if (relaunch) {
			exec("systemctl restart snapcastmpris.service", function(error, stdout, stderr) {
				if (error) {
					if (debug) console.error("Relaunching Snapcast failed: "+error);
					if (callback) callback(false, error);
				} else {
					if (debug) console.error("Snapcast was relaunched.");
					if (callback) callback(true);
				}
			});
		} else {
			if (callback) callback(true);
		}
	/*} else {
		if (callback) callback(false);
	}*/
}
github tjanczuk / git-azure / src / runtime / arr.js View on Github external
function syncRepo(callback) {

	var callbackCalled;

	console.log('Syncing the repo with command ' + config.syncCmd);
	var child = child_process.exec(config.syncCmd, function (err, stdout, stderr) {

		if (callbackCalled) {
			return;
		}

		var isNonEmptyString = function (s) {
			return typeof s === 'string' && s.length > 0;
		}

		if (err) {
			console.log('Failed to sync the repo: ');
			console.log(err);
			if (isNonEmptyString(stderr)) {
				console.log('Stderr of sync command:');
				console.log(stderr);
			}
github Ar3sDevelopment / rpi-systempanel / panelwidgets / processor / processor.js View on Github external
setTimeout(function() {
										exec("cat /proc/stat", function(err, stdout, stderr) {
											if (!err) {
												output2 = stdout.split(/[\n\r]{1,2}/);
												res.cpuload = 0;
												for (var i = 0; i < 1; i++) {
													var cpu_stat_1 = output1[i + 1].split(/\s/);
													var cpu_stat_2 = output2[i + 1].split(/\s/);
													var info1 = {
														user : parseInt(cpu_stat_1[1]),
														nice : parseInt(cpu_stat_1[2]),
														system : parseInt(cpu_stat_1[3]),
														idle : parseInt(cpu_stat_1[4])
													};

													var info2 = {
														user : parseInt(cpu_stat_2[1]),
														nice : parseInt(cpu_stat_2[2]),
github kminami / apib2swagger / bin / apib2swagger.js View on Github external
function extract(filename, callback) {
    console.log('Extracting ' + filename);
    exec('tar xzvf ' + filename, function (err, stdout, stderr) {
        if (err) {
            console.log(stdout);
            console.log(stderr);
            return;
        }
        console.log('Complete!');
        callback();
    });
}
github forsigner / node-pngdefry / postinstall.js View on Github external
var path = require('path');
var fs = require('fs');
var util = require('./lib/util');

if (os.type() === 'Linux') {
  var linuxPath = path.join(process.cwd(), 'lib', 'pngdefry', 'bin', 'linux');
  var pngdefryPath = path.join(process.cwd(), 'lib', 'pngdefry', 'source', 'pngdefry');

  if (!util.fsExistsSync(linuxPath)) {
    fs.mkdirSync(linuxPath);
  }

  var makeFileDir = path.join(process.cwd(), 'lib', 'pngdefry', 'source');
  var command = 'cd ' + makeFileDir + ' && make';

  cp.exec(command, {}, function(error, stdout, stderr) {
    if (error) {
      throw new Error('install fail');
    }

    cp.exec('mv ' + pngdefryPath + ' ' + linuxPath, {});
  });
}
github herozhou / vue-framework-wz / bin / install / plugin / InstallTinymce.js View on Github external
let promise = new Promise(function(resolve, reject){

  	exec(command, (error, stdout, stderr) => {

	   if (error) {
      log(chalk.red('exec error:',error));
        reject(new Error(error));

      return;
    }
    if(stdout!==''){
       log(chalk.green('stdout:',stdout));
    }
    if(stderr!==''){
      log(chalk.red('stderr:',stderr));
    }
        resolve();

  });

child_process

This package name is not currently in use, but was formerly occupied by another package. To avoid malicious use, npm is hanging on to the package name, but loosely, and we'll probably give it to you if you want it.

ISC
Latest version published 8 years ago

Package Health Score

65 / 100
Full package analysis