介绍:
使用方法:
1. 将第一个脚本命名为 test_main.py,将第二个脚本命名为 test_sub.py,并将它们放在同一个目录下
2. 给两个脚本添加执行权限
3. 用 python3 命令执行第一个脚本
第一个脚本:
import subprocess
test=subprocess.Popen(['python3', './test_sub.py'], stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
out=test.decode().strip()
print(out)
第二个脚本:
def sum(a,b):
return(a + b)
c = 4
b = 2
print(sum(c,b))