When I want to redirect an output of a.out program I will use./a.out > output.txtThis doesn't work when the program reads something from stdin.How would you redirect output in this case?I can do it only with./a.out < inputs.txt > output.txtCan I do the same but reading inputs from stdin?EDIT: I realized that it works, but I can't see prompts because everything goes to file output.txt. So, the only problem is to see prompts on stdin and preserve redirection at the same time.
Redirecting output of program reading from stdin
shell;command line;c
One option would be to write your prompts to stderr rather than stdout. They'll be visible on the terminal but not in output.txt.Another option is not to use redirection for your output but take an output filename as a parameter and open that file yourself. You can then use stdout for your prompts. (This is more flexible. You can decide what goes only to the file, what goes only to the screen, and potentially what goes to both.)If you can't change the code, the only option is to use tee or some other such utility. Buffering can be a problem; stdbuf might help with that.