Why is the output of print() functions in Python scripts not captured by > redirection or piping? Itsn't it just going to stdout? I feel like I'm misunderstanding something very basic here, but oh well.


OK the thing I'm encountering is more subtle than I described, but... my script which produces command line output with print functions doesn't put anything into a text file when it's redirected (nor does it apparently provide anything to a pipe)

· · Web · 2 · 0 · 1

Yeah, hm, testing this out with a simpler script is reassuring about my basic understanding of stdout and redirecting, because... it works. but now debugging this is going to be weird

Show thread

figured it out!! I was using os.get_terminal_size() to format the output, but when you redirect it that results in an OSError for "Inappropriate ioctl" (but I was swallowing that error for sloppy reasons)

Show thread

@xor doing anything funny with ncurses or closing file descriptors?

@xor You also might find setting PYTHONUNBUFFERED environment-variable is useful when re-directing, etc..

Sign in to participate in the conversation

The social network of the future: No ads, no corporate surveillance, ethical design, and decentralization! Own your data with Mastodon!