Perl Pipes

A

alertjean

Fellow script writers,
I have two linux executables. I want to give the stand ouput of
executable1 to executable 2.
How can I do it with perl without creating intermediate files ?

something which can be achieved through command line.

$ executable1 > output_file1.txt
$ executable2 output_file1.txt > output_file2.txt


regards
Jean
 
T

Tad J McClellan

Fellow script writers,
I have two linux executables. I want to give the stand ouput of
executable1 to executable 2.
How can I do it with perl without creating intermediate files ?

something which can be achieved through command line.

$ executable1 > output_file1.txt
$ executable2 output_file1.txt > output_file2.txt


The simplest way is to let the shell do it for you:

system 'executable1 | executable2 >output_file2.txt';


Or, if you want to capture the end of the pipeline into your Perl
program rather than into a file:

open my $pipeline, 'executable1 | executable2 |' or die...

Then you can read the data with:

while ( <$pipeline> ) {
...
 
J

Jürgen Exner

I have two linux executables. I want to give the stand ouput of
executable1 to executable 2.
How can I do it with perl without creating intermediate files ?

something which can be achieved through command line.

$ executable1 > output_file1.txt
$ executable2 output_file1.txt > output_file2.txt

Are you looking for something different then a trivial

system ('executable1 | executable2 > output_file2.txt');

jue
 
A

alertjean

The simplest way is to let the shell do it for you:

    system 'executable1 | executable2 >output_file2.txt';

Or, if you want to capture the end of the pipeline into your Perl
program rather than into a file:

    open my $pipeline, 'executable1 | executable2 |' or die...

Then you can read the data with:

    while ( <$pipeline> ) {
        ...


This is what I do currently

system("./CacheSimulator.exe $setsL1 $blockSize $assocL1 $pref_nL1
$pref_mL1 $TraceFile L1_Summary.txt > L1_Traffic_Out.txt");

system("./CacheSimulator.exe $setsL2 $blockSize $assocL2 $pref_nL2
$pref_mL2 L1_Traffic_Out.txt L2_Summary.txt > L2_Traffic_Out.txt");


I want to give L1_Traffic_Out.txt to the second execution

Can I achieve this by the methods you have mentioned ?
 
J

Jürgen Exner

This is what I do currently

system("./CacheSimulator.exe $setsL1 $blockSize $assocL1 $pref_nL1
$pref_mL1 $TraceFile L1_Summary.txt > L1_Traffic_Out.txt");

system("./CacheSimulator.exe $setsL2 $blockSize $assocL2 $pref_nL2
$pref_mL2 L1_Traffic_Out.txt L2_Summary.txt > L2_Traffic_Out.txt");


I want to give L1_Traffic_Out.txt to the second execution
Can I achieve this by the methods you have mentioned ?

That depends solely on ./CacheSimulator.exe. Does it accept input from
STDIN or does it require the file name because it insists on reading
from a file?

jue
 
T

Tad J McClellan

This is what I do currently

system("./CacheSimulator.exe $setsL1 $blockSize $assocL1 $pref_nL1
$pref_mL1 $TraceFile L1_Summary.txt > L1_Traffic_Out.txt");

system("./CacheSimulator.exe $setsL2 $blockSize $assocL2 $pref_nL2
$pref_mL2 L1_Traffic_Out.txt L2_Summary.txt > L2_Traffic_Out.txt");


I want to give L1_Traffic_Out.txt to the second execution

Can I achieve this by the methods you have mentioned ?


What happened when you tried it?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,213
Messages
2,571,108
Members
47,700
Latest member
Naveed baloch

Latest Threads

Top