Shell – How to include program which only works with in/out files into a pipeline

filespipeshell

I need to process image with several tools in a pipeline tool1 | tool2 | tool3 | .... It appeared though that one of the tools isn't designed to work in a pipeline and only works in format of user@computer:/~# bad_tool infile.png outfile.png.

Is there any way to include it into pipeline? I really want to avoid creating files for this only program and then removing them, etc.

Best Answer

if this satisfies you, here is proposition how to do this using pipes.

Assumption is that input and output files of "badtool" can be pipes.

mkfifo IF
mkfifo OF

# one therminal
tool | tool2 |... tooln > IF

# second terminal
bad_tool IF OF

#third terminal
tooln+1 < OF | tool n+2 | tool n+3 ...

If you would like to create script you can wrap those parts into functions:

function A(){ ... }
function B(){ ... }
function C(){ ... }
# and run in background in parallel
A&
B&
C&

Continue with all your images (pipes IF and OF are "reusable") and after whole job delete them

rm IF OF
Related Question