Execute a command line binary with Node.js

后端 未结 12 2544
星月不相逢
星月不相逢 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 01:59

    Since version 4 the closest alternative is child_process.execSync method:

    const {execSync} = require('child_process');
    
    let output = execSync('prince -v builds/pdf/book.html -o builds/pdf/book.pdf');
    

    ⚠️ Note that execSync call blocks event loop.

提交回复
热议问题