0

I have used gcc and make to compile a c file. The name of the run file is sequence. I have two goals:

  1. Have an input file (i.ein1) as stdin and run the program. when the program finishes using in1 and terminates, run it again with a different input file (i.e in2 specified in the terminal command.
  2. Have all the outputs from all the different times the program executed go to the same file (i.eoutput1), without overriding the previous inputs. So the result will be something like this:

Input files:

in1:

a

in2:

b

in3

c

In program:

putchar(getchar());

Output:

a
b
c

How can I achieve the expected result via terminal command?

muru
  • 72,889

1 Answers1

0

You seem to be mixing up what is the responsibility of the shell, and the responsibility of a program.

You have two choices

Have the program open 3 files, and write them to stdout. This is what cat does.

program in1 in2 in3

Use shell-redirection-append >>.

E.g.

program <in1 >> file-name
program <in2 >> file-name
program <in3 >> file-name

or use brackets, and over-writing-redirection

{
  program <in1
  program <in2
  program <in3
} > file-name