puppeteer 执行本地可执行文件

4 min read

示例

const exec = require('await-exec')

async function test(){
    let data = await exec("'./mac'")
    console.log('data',data.stdout)
}

test();

用法

Small promise wrapper around node's child_process#exec allowing you to use async/await syntax for commands you want to execute.

const exec = require('await-exec')
 
async function logger (text) {
  await exec(`echo ${text}`)
}
 
for (let k = 0; k < 10; k++) {
  logger('worked!')
}

Optinally you can pass a second Object that will get directly passed to cp#exec