Without pointing out ten different libraries to do this a different way, can anyone tell me why python restarts my script when STDOUT is redirected on the command line? (running on CentOS 7)
#!/usr/bin/python
import os
print("Top of the script")
pid = os.fork()
print("Pid: " + str(os.getpid()))
Regular output is:
$ ./forktst2.py
Top of the script
Pid: 1919
Pid: 1920
But when I pipe it to anything it becomes:
$ ./forktst2.py | cat
Top of the script
Pid: 2151
Top of the script
Pid: 2153
Which is doubly confusing because if it's rerunning the first print()
then why isn't it also rerunning os.fork()
?
Thanks!