perldoc -f open for more information.open FILE, "|du -sk|" or die "$!"; print FILE `ls`; print while(<FILE>);
Edit: This is false... :(
As noted in the replies, IPC::Open2 was the correct solution. From perldoc IPC::Open2:
The open2() function runs the given $cmd and connects $rdrfh for reading and $wtrfh for writing. It's what you think should work when you try $pid = open(HANDLE, "|cmd args|"); The write filehandle will have autoflush turned on.
That was what confused my. I'm sorry for the error.
This is the syntax for Open2:
use IPC::Open2; $pid = open2(\*RDRFH, \*WTRFH, 'some cmd and args'); # or without using the shell $pid = open2(\*RDRFH, \*WTRFH, 'some', 'cmd', 'and', 'args'); # or with handle autovivification my($rdrfh, $wtrfh); $pid = open2($rdrfh, $wtrfh, 'some cmd and args'); # or without using the shell $pid = open2($rdrfh, $wtrfh, 'some', 'cmd', 'and', 'args');
Open3 gives you also STDERR.
In reply to Re: pretending that the contents of a variable are files
by deibyz
in thread pretending that the contents of a variable are files
by marcokuma
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |