Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
node <> Perl communication over additional fds
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
You can’t perform that action at this time.