我正在尝试编写一个脚本,该脚本使用子进程将变量从脚本1传递给脚本2,然后脚本2将变量传递给脚本3。但是我只能从脚本1和2获得答复。
我希望离开的是:
TOM
迪克
哈里
你好
但是我得到的是:
TOM
你好
我正在使用的代码是:
脚本1
import subprocess
pythonExecutable = 'C:\\Users\\bradl\\Anaconda2\\envs\\GeoSpatial_3.6\\python.exe'
varTest_1 = "Tom"
program = 'D:\\Training\\FromCommandLine\\Script_2.py'
subprocessList1 = [pythonExecutable, program, varTest_1]
p1 = subprocess.Popen(subprocessList1, stdout=subprocess.PIPE, stdin=subprocess.PIPE)
out1, err1 = p1.communicate()
print(out1.decode('utf-8'))
脚本2
import sys
import subprocess
pythonExecutable = 'C:\\Users\\bradl\\Anaconda2\\envs\\GeoSpatial_3.6\\python.exe'
program = 'D:\\Training\\FromCommandLine\\Script_3.py'
varTest_2 = sys.argv[1]
print(str(varTest_2).upper())
varTest_3 = "Dick"
subprocessList2 = [pythonExecutable, program, varTest_3]
p2 = subprocess.Popen(subprocessList2, stdout=subprocess.PIPE, stdin=subprocess.PIPE)
out2, err2 = p2.communicate()
print(out2.decode('utf-8'))
print('Hello')
脚本3
import sys
varTest_4 = sys.argv[1]
print(varTest_4)
print(str(varTest_4).upper())
print('Harry')
任何帮助将不胜感激!