0

I wrote a program, that shows a terminal UI with python curses. The program shall be able to read from STDIN and write the result after the user interaction to STDOUT w/o so the output may be redirected to another program or file like so: cat in.csv | my_tool > out.csv

I figured out a working solution for STDIN to not interfere with curses (Linux: Pipe into Python (ncurses) script, stdin and termios).

I also found several solutions to redirect STDOUT temporarily to a file (Redirect stdout to a file in Python?)

If I read this right, it is possible in C. But the newterm function is not exposed in the python wrapper?

Benjamin
  • 1,726
  • 1
  • 14
  • 35
  • Could it be an option to just write to STDERR? – Serge Ballesta Dec 23 '21 at 13:39
  • I am looking for a solution, that is transparent to the user. So w/o the need to redirect streams when using the program as described above. – Benjamin Dec 23 '21 at 13:41
  • 1
    Writing to stdout what is expected to be redirected and to stderr what is not, is just what I learned in the early 80's, and what I still use... – Serge Ballesta Dec 23 '21 at 13:45
  • I think you are conflating the terminal with stdout. If the user redirects stdout to a file, then stdout *is* the file. If you want to write to the controlling terminal, you cannot do so by manipulating stdout. You need to write to the controlling terminal. – William Pursell Dec 23 '21 at 15:03

0 Answers0