Jun-12-2017, 07:47 PM
Folks,
I'm trying to checkout the sub-process functionality of Python and am having some trouble, specifically on the subprocess accepting stdin...
here is my masterPrint.py
C:\Users\oahmad>py -2 masterPrint.py
enter a number between 1 and 102
Traceback (most recent call last):
File "slavePrint.py", line 1, in <module>
a = input()
File "<string>", line 1, in <module>
NameError: name 'hello' is not defined
enter a number between 1 and 10
I'm trying to checkout the sub-process functionality of Python and am having some trouble, specifically on the subprocess accepting stdin...
here is my masterPrint.py
import subprocess #subprocess.call(["python", "slavePrint.py"], shell=True) #stdout of subprocess is piped to p #stdin of subprocess is piped to p p = subprocess.Popen(["python", "slavePrint.py"], stdout=subprocess.PIPE, stdin=subprocess.PIPE) while(1): #read in string strng = input("enter a number between 1 and 10") str = p.communicate(str(strng)+ '\n')[0] print strhere is my slavePrint.py
a = input() print ('slave got ' + str(a))Here is the error I am getting when I run the code:
C:\Users\oahmad>py -2 masterPrint.py
enter a number between 1 and 102
Traceback (most recent call last):
File "slavePrint.py", line 1, in <module>
a = input()
File "<string>", line 1, in <module>
NameError: name 'hello' is not defined
enter a number between 1 and 10