In article <w0HZc.502$H26. 135@trnddc07>, Jürgen Exner
<ju******@hotma il.com> wrote:
R Evans wrote: Hello,
In a Perl script, I run a program, Program.pl, by using:
@output = `cat $file_name | Program.pl`;
Useless use of cat. Why not
Program.pl < $file_name
However I want to run this program when the contents of the file named
$file_name are stored in a string variable called $file_contents, as I
don't have permission to store them in a file. So I want to capture
something like:
@output = `cat $file_contents | Program.pl`;
Does anyone know how this can be done?
You mean something like
@output = `echo $file_contents | Program.pl`;
I think the poster means that $file_contents contains the _contents_ of
the file, not the name (i.e. { local $/; $file_contents = <FILE> } ).
In that case, you can do something like (untested):
open(EXE,'|Prog ram.pl') or die $!;
print EXE $file_contents;
See 'perldoc -f open' and 'perldoc perlipc'. If you also want to
capture the output of the program, then you need to see IPC::Open2 and
IPC::Open3, which may not be supported on all platforms.