in reply to pretending that the contents of a variable are files
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.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: pretending that the contents of a variable are files
by chb (Deacon) on Jan 28, 2005 at 12:39 UTC | |
|
Re^2: pretending that the contents of a variable are files
by merlyn (Sage) on Jan 28, 2005 at 12:35 UTC |