js execFile

原文链接: js execFile

上一篇: node 整合外部应用

下一篇: js spawn

execFile

执行外部程序, 并且需要提供一组参数, 以及一个在进程退出后的缓存输出的回调

当你只需要执行一个外部程序的时候使用它, 这种方法的执行速度快, 使用简便, 并且在处理有用户输入时相对更加安全

const cp = require('child_process')
cp.execFile("echo", ['hello', 'world'], (err, stdout, stderr) => {
  // if (err) console.error(err)
  console.log('stdout:', stdout)
  console.log('stderr:', stderr)
})





// 添加环境变量, 绝对路径或者相对路径都可以
cp.execFile('./abcd')
cp.execFile('node',['echo.js'])

console.log(process.env.PATH.split(':').join('\n'))
cp.execFile("pwd", [], (err, stdout, stderr) => {
  // if (err) console.error(err)
  console.log('stdout:', stdout)
  console.log('stderr:', stderr)
})

cc98b45a8b00c37bd376ef6c377f171eb44.jpg

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值