Bash redirect stdout to stdin (last update: 2015-06-21, created: 2015-06-21) back to the list ↑
How to redirect stdout of a given application to stdin of the same application, using a temporary file (if you can do it without a file, please let me know). Please note there is no magic here (pieces are described in the Bash manual linked at the end of this note) and it works only under Linux (as it doesn't lock files opened for writing, as Windows does by default).

Example application in Python 2.7:


import sys

print "STDOUTDATA"
sys.stdout.flush()
with open("logpy", "w") as f:
    f.write(sys.stdin.readline())


How to run and test:


> python t2.py <>somefile >somefile
> cat somefile
STDOUTDATA
> cat logpy
STDOUTDATA
>


See also: Bash manual / 3.6 Redirections
【 design & art by Xa / Gynvael Coldwind 】 【 logo font (birdman regular) by utopiafonts / Dale Harris 】