How to redirect stream to multiple files?

Interested in how to implement what you can do in the command prompt:
ls > file1 > file2
If one file, then everything is clear: use dup2() to replace STDOUT_FILENO fd on the desired file, but if you need several...
The only thing I can think of is to run the child process, which will sit on the STDOUT_FILENO and manually write in each fd.
Can anyone have better solution?
April 3rd 20 at 17:22
1 answer
April 3rd 20 at 17:24
Solution
how to realize what you can do in the command prompt:
ls > file1 > file2

This command line does not redirect stream to multiple files. Output falls only in one of them. The second file is created but remains empty.
Redirect output to multiple files using the command tee:
ls | tee file1 file2

The only thing I can think of...manually recorded in each fd.

Yes.

Find more questions by tags CStandard streams