sub_test.py
import subprocess
p=subprocess.Popen(['python3', './test.py', '1', '2'], stdin = subprocess.PIPE, stdout=subprocess.PIPE)
out=p.stdout.readlines()
print(out)
test.py
import sys
def sum(a, b):
return(a + b)
if __name__ == "__main__":
a = sys.argv[1]
b = sys.argv[2]
print(sum(int(a), int(b)))
运行 python3 sub_test.py
test.py 相当于sub_test.py的子进程,sub_test.py输出的是test.py内所有print()的内容