Skip to content Skip to sidebar Skip to footer

ExecSync In Node.js Doesn't Run Shell Command Properly

I'm trying to run a child_process.execSync shell command in node.js like this: function test() { return new Promise(function(resolve, reject) { var execSync = require('

Solution 1:

if the last exec program return error code for example on this C code

#include <stdio.h>

int main(void)
{

    printf("hi");

    return 1;
}

the point is if the program not return 0 the node child_process throw error

My Answer :

const proc = require('child_process');

// just add " || true" after your command 
var output = proc.execSync('command || true');

it's work fine for me :)


Post a Comment for "ExecSync In Node.js Doesn't Run Shell Command Properly"