1

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   .......
2
  • 1
    How does this relate to C? Are you asking about shell redirection? Commented Oct 15, 2015 at 19:48
  • 1
    if you want to send file1, file2... as input for stdin to a program you just have to use catcat file1 file2 file3 | ./my_program. And it has nothing related to C. Commented Oct 15, 2015 at 19:52

1 Answer 1

4

Probably what you are looking for is

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

which will use cat to concatenate 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)
Sign up to request clarification or add additional context in comments.

1 Comment

that's it. thanks a lot rici. novice question, i know. i appreciate your time and patience.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.