How to inherit stdin and stdout in python by using os.execv()
问题 First, I wrote a c++ code as follows: #include <cstdio> int main() { int a,b; while(scanf("%d %d",&a,&b) == 2) printf("%d\n",a+b); return 0; } I use g++ -o a a.cpp to complie it. Afterwards, I wrote python code as follows: import os,sys sys.stdin = open("./data.in","r") sys.stdout = open("./data.out","w") pid = os.fork() if pid == 0: cmd = ["./a","./a"] os.execv(cmd[0],cmd) However, the data.out file contains nothing. That is to say, the child process did not inherit stdin and stdout from his