0

I'm trying to write a script which pass a variable from Script 1 to Script 2, then Script 2 pass a variable to Script 3 using subprocess. But I am only get responses from Scripts 1 and 2.

What I am expecting to get out is:

TOM
Dick
Harry
Hello

But what I'm getting is:

TOM

Hello

The Code I'm using is:

Script 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'))

Script 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')

Script 3

import sys

varTest_4 = sys.argv[1]
print(varTest_4)
print(str(varTest_4).upper())
print('Harry')

Any help would be appreciated!

3
  • It works good to me. I got TOM Dick DICK Harry Hello Commented Sep 19, 2018 at 13:48
  • 1
    Running Python as a subprocess of itself is often a poor solution anyway. Perhaps see stackoverflow.com/questions/48395685/… Commented Sep 19, 2018 at 13:51
  • Cheers, I'll check that out Commented Sep 19, 2018 at 13:56

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.