node.js - NodeJS子进程在同一个shell中执行2个命令
问题描述
我想在同一个 shell 中使用 nodeJS 运行 2 个命令。但是,文档似乎只能运行一个命令child_process.spawn(command[, args][, options])
必须在同一个 shell 中执行 2 个命令的原因是因为第一个脚本将写入环境,而第二个脚本将从环境中读取。
这是脚本的一个示例,但我希望 ps 和 grep 都在同一个 shell 中。
const { spawn } = require('child_process');
const ps = spawn('ps', ['ax'], { shell: true });
const grep = spawn('grep', ['ssh'],{ shell: true });
解决方案
尝试
ps.stdout.pipe(grep.stdin);
推荐阅读
- javascript - Javascript使用正则表达式获取对象中间的日期
- linux - 为什么 python 程序在 Linux shell 和 Jenkins 作业之间运行结果不同
- django - stefanfoulis/django-phonenumber-field 模板中电话号码的显示格式
- python - 使用 python 和 pyttsx3 为自动售货机制作谈话清单。如何通过列表返回?
- vue.js - Workbox/Vue:在现有缓存策略处理程序上创建自定义变体
- html - 如何将文本浮动到右侧,同时使其与它所在的 div 内联?
- html - 手机号码键盘在 Iphone 中不起作用
- python-3.x - 在 Pandas 中逐行解包 JSON 转储并将其键用作单独的列需要很长时间
- html - 具有动态数据的 django 模板表单目标
- python - 我scapy通过ppp链接发送数据包,为什么sr收不到回复?tcpdump ppp0 没问题