0

I'm writing a program prog that is run from the terminal and (for now) performs the same function as an existing program eprog.

I would like to be able to my program against the existing one by writing a third program in C that:

  • Takes input from (stdin)
  • Sends that input to both prog and eprog
  • Compares the terminal output from each, printing an error if they differ or else exiting normally.

What would be the best way to implement this? I'm aware of the existence of fork(), but have never used it and am not sure if it is the more appropriate solution here.

Kostas7
  • 27
  • 7
  • 1
    You might be able to do that without writing any extra program - perhaps you could `tee` the program and redirect the two stdout's to two FIFO queues, then run `diff` on them. – LSerni Oct 12 '18 at 22:24
  • If you do choose to write the third program, then I believe you need `pipe`, `fork`, `dup2`, and `execv` in roughly that order (and multiple calls to each since you need to create two child processes). – user3386109 Oct 12 '18 at 22:28
  • Does it have to be a C program? If not, and if you're on a UNIX-like environment (Mac, Linux or similar), you can do this pretty straightforwardly with existing shell utilities, and it will be easier than writing a C program to do it yourself. If your environment would allow for something like this, I'd suggest editing the question to say so. – David Z Oct 12 '18 at 22:29
  • @LSerni That would certainly be possible, but I'l like to keep it as a separate program so that it is of the same type as the rest of my tests, and also so that I would be able to use e.g. afl or something with it later. – Kostas7 Oct 12 '18 at 22:30
  • @DavidZ It wouldn't be impossible to do it with only the shell, except I'd like to keep it as a separate program so that it is of the same type as the rest of my tests, and also so that I would be able to use e.g. afl or something with it later. – Kostas7 Oct 12 '18 at 22:32
  • [This question](https://stackoverflow.com/questions/916900) may be of assistance. – user3386109 Oct 12 '18 at 22:33

0 Answers0