nodejs 启动第三方exe

  1. nodejs启动第三方的exe、传入启动参数,并设置工作路径,代码如下
js 复制代码
const iconv = require('iconv-lite'); # 解决乱码问题
const { spawn } = require('child_process');

function say() {
  const exePath = 'D:/helle.exe';	// exe绝对路径
  const args = ['argc1', 'argc2', 'argc3']; // exe启动参数
  const options = {
    cwd: 'D:/work'					// 设置exe工作路径
  };
  const childProcess = spawn(exePath, args, options);
  // 监听子进程的输出
  childProcess.stdout.on('data', (data) => {
    console.log(`stdout: ${iconv.decode(data, 'gbk')}`);
  });

  childProcess.stderr.on('data', (data) => {
    console.error(`stderr: ${iconv.decode(data, 'gbk')}`);
  });

  // 监听子进程的退出
  childProcess.on('close', (code) => {
    console.log(`子进程退出,退出码 ${code}`);
  });
}

function execute(someFunction) {
  someFunction();
}

execute(say);
相关推荐
小小编程路4 分钟前
C++ 异常 完整讲解
开发语言·c++
AI科技星42 分钟前
数术工坊 · 第四卷 橡皮泥江湖(拓扑学)【完整定稿】
c语言·开发语言·汇编·electron·概率论·拓扑学
张忠琳1 小时前
【Go 1.26.4】Golang Select 深度解析
开发语言·后端·golang
AC赳赳老秦2 小时前
OpenClaw+Power Apps 实战:自动生成 Power Apps 应用、连接 Excel 数据源
大数据·开发语言·python·serverless·excel·deepseek·openclaw
提笔了无痕2 小时前
如何用Go实现整套RAG流程
开发语言·后端·golang
(Charon)2 小时前
【C++ 面试高频基础:指针、引用、const、static、new/delete 总结】
java·开发语言
2601_961875243 小时前
法考考试时间安排及科目|时间表|资料已整理
开发语言·c#·inverted-index·suffix-tree·sstable·r-tree·lsm-tree
AI科技星3 小时前
数术工坊第八卷:算力革命
c语言·开发语言·网络·量子计算·agi
geovindu3 小时前
go: Generators Pattern
开发语言·后端·设计模式·golang·生成器模式
码云骑士4 小时前
13-列表append的底层真相(上)-listobject源码中的预分配策略
开发语言·python