Execute a command line binary with Node.js

后端 未结 12 2242
星月不相逢
星月不相逢 2020-11-22 01:39

I am in the process of porting a CLI library from Ruby over to Node.js. In my code I execute several third party binaries when necessary. I am not sure how best to accomplis

12条回答
  •  鱼传尺愫
    2020-11-22 02:19

    If you want something that closely resembles the top answer but is also synchronous then this will work.

    var execSync = require('child_process').execSync;
    var cmd = "echo 'hello world'";
    
    var options = {
      encoding: 'utf8'
    };
    
    console.log(execSync(cmd, options));
    

提交回复
热议问题