Created
April 14, 2019 21:49
-
-
Save hoehrmann/bae3432a01fb4dc627c27dbc3a33d833 to your computer and use it in GitHub Desktop.
node <> Perl communication over additional fds
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { spawn } from 'child_process'; | |
import { Writable, Readable } from 'stream'; | |
const child = spawn( | |
'perl', | |
['-e', ` | |
use IO::Handle; | |
my $in = IO::Handle->new_from_fd($ENV{JIPE_RHS_STDIN_FD}, 'r'); | |
my $out = IO::Handle->new_from_fd($ENV{JIPE_RHS_STDOUT_FD}, 'w'); | |
$out->autoflush(1); | |
while (<$in>) { | |
print $out $_; | |
} | |
`], | |
{ | |
env: { | |
...process.env, | |
JIPE_RHS_STDOUT_FD: `3`, | |
JIPE_RHS_STDIN_FD: `4`, | |
}, | |
shell: false, | |
stdio: ['pipe', 'pipe', 'inherit', 'pipe', 'pipe'] | |
} | |
); | |
const childStdout: Readable = child.stdio[3] as Readable; | |
const childStdin: Writable = child.stdio[4] as Writable; | |
childStdout.on('data', data => { | |
console.error('child said', data.toString()); | |
}) | |
childStdin.write(`Hello\n`); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment