how to redirect multiple input files?

I have a program that runs like "cat f1 - f2 -", I need to write shell script to run the program whose standard input will be redirected from 2 files. I spend a whole day on it, but didn't figure out. Can someone help me out? Thanks!

not exactly sure what your requirement is, but it sounds like:

redirect standard in from 2 files at the same time to a single process

that is done like this:

cat f1 f2|process

or this

process<cat f1 f2

'cat' concatenates the files, so this is nearly equivalent to the following:

process < f1
process < f2

Thanks for your reply. But it still does not work. It says "cat: No such file or directory".
My program command can run like this: "./a.out file1.txt - file2.txt -", when the parameter is a file name, it will read file content, otherwise, when the parameter is a hyphen, it will read from stdin(just like "cat file1 - file2 -"). I need write a test script to run this program, however, I don't know how to redirect two file for stdin. Anybody can help me? Thanks.

can you post your script?

the error means that one of the arguments you are passing to 'cat' is not a file, or doesn't exist on the path you've indicated--however without seeing how you are calling 'cat' in your script, I can only speculate.

the code you have is treating cat as a file name.

process<cat f1 f2

to use this method you will need to do it in two steps

cat f1 f2 >/tmp/foo
process</tmp/foo

I don't really understand the requirements so I am not sure how to provide a solution. Having parameters like <file1> <-> <file2> <-> just does not seem right. What is the end result you are looking for?

You cannot redirect from a command with <; the argument must be a file.

If your shell has process substitution, you can do:

process < <(cat f1 f2)

Or use a here document:

process <<.
$( cat f1 f2 )
.

good point cfa. thx.

Thanks. But I still do not know how to resolve the problem.
The program is launched by following command,

prog file1 - file2 -

When I enter the command, it will process file1, and then read from stdin(-) until I enter Ctrl D. and then process file2, and then read from stdin(-) until Ctrl D.

I can embed the data from stdin into shell script. How do I do this in the script without any interactive input? Because there are two EOF, perhaps I also can not use here doc. Struglling for 2 days... Thanks.

You could try putting a ^D in the here document (in vi by entering Ctrl-v followed by Ctrl-d) and see if that works, otherwise perhaps an expect script may be a better way to go.