I know how to detect if my Python script’s stdout is being redirected (>) using sys.stdout.isatty() but is there a way to discover what it’s being redirected to?
For example:
python my.py > somefile.txt
Is there a way to discover the name somefile.txt on both Windows and Linux?
I doubt you can do that in a system-independent way. On Linux, the following works: