How to use the spawnSync function from child_process

Find comprehensive JavaScript child_process.spawnSync code examples handpicked from public code repositorys.

1
2
3
4
5
6
7
8
9
10

const path = require('path');
const proc = require('child_process');
const fs = require('fs');

const findResult = proc.spawnSync('find', ['.', '-iname', '"_*.scss"'], {
  cwd: __dirname,
  shell: true,
  env: process.env,
}).stdout.toString();
fork icon0
star icon4
watch icon4

+ 5 other calls in file

98
99
100
101
102
103
104
105
106
107
                cwd: __dirname,
                encoding: 'utf8',
                shell: true,
        }),
onComplete: () =>
        spawnSync('yarn', ['run', 'icons:apply'], {
                cwd: __dirname,
                encoding: 'utf8',
                shell: true,
        }),
fork icon967
star icon0
watch icon87

+ 3 other calls in file

24
25
26
27
28
29
30
31
32
33
34
    return path.join(__dirname, "fixtures", filename);
  }
}


function runPhp(args, stdin) {
  const result = cp.spawnSync("php", args, {
    input: stdin || null,
    encoding: "utf8",
  });
  if (result.error) {
fork icon1
star icon4
watch icon1

468
469
470
471
472
473
474
475
476
477
478
});


gulp.task('validatePackageLockJson', async () => {
    const fileName = path.join(__dirname, 'package-lock.json');
    const oldContents = fs.readFileSync(fileName).toString();
    spawnSync('npm', ['install', '--prefer-offline']);
    const newContents = fs.readFileSync(fileName).toString();
    if (oldContents.trim() !== newContents.trim()) {
        throw new Error('package-lock.json has changed after running `npm install`');
    }
fork icon0
star icon4
watch icon0

+ 3 other calls in file

1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
execFile('bash', ['/home/revo/nodeutils', '-showmaster'], (errShowMaster, stdoutShowMaster, stderrShowMaster) => {
  if (errShowMaster) {
    res.status(404).send(errShowMaster);
  } else {
    //let result = execFileSync('bash', ['/home/revo/nodeutils', '-listunspent', stdoutShowMaster.slice(0, stdoutShowMaster.length - 1 )], { encoding: 'utf8' });
    let result = spawnSync('bash', ['/home/revo/nodeutils', '-listunspent', stdoutShowMaster.slice(0, stdoutShowMaster.length - 1 )], { encoding: 'utf8' });    
    let outtext = result.output[1]
    let outputresult = outtext.replaceAll("\n", "");
    res.send(outputresult);        
  }
fork icon0
star icon1
watch icon1

+ 14 other calls in file

204
205
206
207
208
209
210
211
212
213

log.info("plugin", "Installing dependencies");

if (fs.existsSync(indexFile)) {
    // Install dependencies
    let result = childProcess.spawnSync("npm", [ "install" ], {
        cwd: this.pluginDir,
        env: {
            ...process.env,
            PLAYWRIGHT_BROWSERS_PATH: "../../browsers",    // Special handling for read-browser-monitor
fork icon0
star icon0
watch icon1

16
17
18
19
20
21
22
23
24
25
26
27


const rootDir = path.resolve(dirName, '..', '..', '..', '..', '..')
const herondCoreDir = path.join(rootDir, 'src', 'herond')


const run = (cmd, args = []) => {
  const prog = spawnSync(cmd, args)
  if (prog.status !== 0) {
    console.log(prog.stdout && prog.stdout.toString())
    console.error(prog.stderr && prog.stderr.toString())
    process.exit(1)
fork icon0
star icon0
watch icon1

+ 2 other calls in file

88
89
90
91
92
93
94
95
96
97
98
99
100


const util = {


  runProcess: (cmd, args = [], options = {}) => {
    Log.command(options.cwd, cmd, args)
    return spawnSync(cmd, args, options)
  },


  run: (cmd, args = [], options = {}) => {
    const { continueOnFail, ...cmdOptions } = options
fork icon0
star icon0
watch icon1

+ 2 other calls in file