簡體   English   中英

NodeJS子進程在同一個shell中執行2個命令

[英]NodeJS Child Process execute 2 command in the same shell

我想在同一個 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);

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM