I'm generating a script with Perl and i want to run it through node.js, as a javascript interpreter. I want to know how to run the $script without writing it to disk and then calling node, afterwards capturing the output. I'm using the system command, wich i think is good for this pourpose.
Use open
instead of system
#!/usr/bin/perl
open(FOO, "|node");
print FOO "console.log('hello world');";
Or if you don't need to do it from inside the perl script, just from your shell:
$ ./myscript.pl | node
Where myscript.pl
exits after printing the javascript code
Use IPC::Run or IPC::Open3.
use strictures;
use IPC::Run qw(run);
use autodie qw(:all run);
my $in = '… JavaScript goes here …';
my $out;
run ['node'], \$in, \$out;