I execute a system command and want to (1) preload STDIN for the system command and (2) grab STDOUT from the command.
Per here. I see that I can do this:
open(SPLAT, "stuff") || die "can't open stuff: $!";
open(STDIN, "<&SPLAT") || die "can't dupe SPLAT: $!";
print STDOUT `sort`;
In this case, STDIN is currently used as STDIN for sorting. This is great if I have data in a file, but I have it in a variable. Is there a way to load the contents of a variable into STDIN before executing a system command? Sort of:
open(STDIN, "<$myvariable");
print STDOUT `sort`;
Can this be done without using a temporary file? Also, I'm on Windows, so Open2 is not recommended, I hear.
Thank.
source
share