I'm using python to os.fork
a child progress, and use os.execv
to execute another program in the child progress. How can I redirect I/O in the child program. I tried this but failed.
import sys, os
pid = os.fork()
if pid is 0:
sys.stdin = open('./test.in')
os.execv('/usr/bin/python', ['python', './test.py'])
While test.py
is:
import sys
print(sys.stdin)
a = input()
print(a)