[英]Send the stdout of spawnSync to another spawnSync stdin
How do I emulate linux's | 我如何模拟linux的| (pipe) in a node.js app to pipe the stdout
of a command to the stdin
of the next command. (pipe)在node.js应用程序中,以将命令的stdout
通过管道传递到下一个命令的stdin
。 Both commands are being spawned with spawnSync
. 这两个命令都使用spawnSync
。
This (pseudo code) works as expected in the commandline: 此(伪代码)在命令行中按预期工作:
$ command1 -arg1 file | command2 arg2
> someoutput
But this does not: 但这不是:
const spawnSync = require('child_process').spawnSync;
const c1Spawn = spawnSync('command1', ['arg1', 'file']);
const c2Spawn = spawnSync('command2', ['arg2'], { input: c1Spawn.output });
const someoutput = c2Spawn.output;
I believe I found the answer by using input: c1Spawn.stdout
instead of output as the in for the second command. 我相信我可以通过input: c1Spawn.stdout
找到答案input: c1Spawn.stdout
而不是第二条命令的input: c1Spawn.stdout
in。
const spawnSync = require('child_process').spawnSync;
const c1Spawn = spawnSync('command1', ['arg1', 'file']);
const c2Spawn = spawnSync('command2', ['arg2'], { input: c1Spawn.stdout });
const someoutput = c2Spawn.output;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.