Execute a command line binary with Node.js

后端 未结 12 2226
星月不相逢
星月不相逢 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:09

    Use this lightweight npm package: system-commands

    Look at it here.

    Import it like this:

    const system = require('system-commands')
    

    Run commands like this:

    system('ls').then(output => {
        console.log(output)
    }).catch(error => {
        console.error(error)
    })
    

提交回复
热议问题