PIpe Spy

Im trying to get my program to behave in this way:

prog 1 | ./pipespy myfile.dat | prog2

the standard output of prog1 is supplied as the input to prog2 and copied into file myfile.dat.

need help

You want the tee command.

prog 1 | tee myfile.dat | prog 2

If you want to append to myfile.dat, use:

prog 1 | tee -a myfile.dat | prog 2

What's PipeSpy btw?

pipespy is a C++ program i was thinking of writing.
you prog1 and prog2 what type of files should it be? like should it be a C++ program,or just like text file?

Prog1 and Prog2 are any program (such as c++) or script(which is a text file) you want them to be... as long as Prog1 would normally send output to the screen, my line of code will redirect it into "myfile.dat" and also send it to "Prog2".

Perhaps it could work out this way:

prog 1 | ./pipespy myfile.dat | prog2

The executable 'pipespy' should read the standard input and before writing the data to standard output store it within a file named 'myfile.dat'

these can be any executables. see the man pages for 'tee' and it gives a simple example using grep and wc.

hey guys,thanks for a all your help,but i cant seem to get it working.i created prog1 and prog2 has a .txt file,and i keep getting

aspasia$ prog1.txt | tee -a myfile.dat | prog2.txt
-bash: prog1.txt: command not found
-bash: prog2.txt: command not found

any suggestions?

no no no no no, those have to be EXECUTABLES. you can not *execute* a text file. a text file simply contains DATA. obviously you will get a "command not found" error, because prog1.txt and prog2.txt are not commands. understand?

program1 is executed, the output is then piped ( | ) to tee, tee takes a filename as an argument, and dumps the output from program1 to the given filename, at the same time, tee also outputs (dumps to the screen) the output from program1, which you then pipe to program2.

S.P., what kind of a solution is that? You've restated the problem... :rolleyes:

I'm wondering, jodders - are prog1.txt and prog2.txt actually scripts? Or do they just contain some data? Like norsk said, simple text files can't be executed. If these are scripts, then read up on the "chmod" command.

ok cheers guys.i guess i have to make it an executable C++ file.What data can i put? i could have like a print out "hello world" thing couldn't i ?LIke a very simple command.What do i put in prog2? If its going to pipe to prog2,do i create an empty executable?

Wow, looking at this thread, it's resembling homework more and more... can you tell us what exactly you're trying to do jodders? Like what you're actually trying to accomplish, since no one decides to just create some programs to pipe into each other...

Originally posted by oombera
S.P., what kind of a solution is that? You've restated the problem...

The problem was:
prog 1 | ./pipespy myfile.dat | prog2

the standard output of prog1 is supplied as the input to prog2 and copied into file myfile.dat.

And if you create an executable(pipespy) which reads standard input stream and stores data read into a file before it writes back to the standard output will achieve the objective.