简体   繁体   中英

Multiple input text files as stdin under unix

new to Linux and C so probably a simple task..but
As per the title,

How, via the command line, do you redirect 2 distinct files as input, so that when the program is done with the first, it will move on to the second?

./a.out < in1.txt   .......

Probably what you are looking for is

cat in1.txt in2.txt ... | ./a.out

which will use cat to con cat enate the named files to stdout, and the | (pipe) operator to take the stdout from the left and feed it into the stdin on the right.

./a.out > in1.txt

redirects stdout , not stdin. If you want to redirect stdin, use

./a.out < in1.txt

But you can only specify one file.

With bash, you can also redirect from the output of a command:

./a.out < <(cat in1.txt in2.txt)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM