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.


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

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

rm IF OF
| improve this answer | |
  • Do I need to do something with these pipes IF and OF after I finished using them? – bazzilic Jun 7 '12 at 10:47
  • 1
    Answer updated acording to your question. Yes: you need to delete them after whole job. But they are reusable so you can use this pair for all files (assuming you are not going to use them in parallel -> in such case, one pair for each thread) – Grzegorz Wierzowiecki Jun 7 '12 at 11:00

If the pipeline normally would be:

tool1 | tool2 | tool3

but tool2 is the “bad” one which requires 2 parameters (1st the input file, 2nd the output file), you can rewrite it like this:

tool2 <(tool1) >(tool3)

Of course, if your shell supports process substitution.

| improve this answer | |
  • They good idea in general. In practice it's implemented in same way as proposed mkfifo "manual pipeing". So depending on length of script it might be more convenient either to use sorter t <(X) >(Y) form , either to split it into sections. As I understood from problem statement - there are MANY tool, so that's why I proposed the same, but in form allowing to split stuff into sections -> for improving code readability. – Grzegorz Wierzowiecki Jun 7 '12 at 11:03

If this is linux, you can do

bad_tool /dev/stdin /dev/stdout

/dev/stdin and /dev/stdout are just symlinks to /proc/self/fd/{0,1} (respectively).

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.