Python Forum
trying out subprocess in python
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
trying out subprocess in python
#1
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

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 str
here 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
Reply


Messages In This Thread
trying out subprocess in python - by sblu23 - Jun-12-2017, 07:47 PM
RE: trying out subprocess in python - by wavic - Jun-12-2017, 10:09 PM
RE: trying out subprocess in python - by sblu23 - Jun-13-2017, 12:01 AM
RE: trying out subprocess in python - by nilamo - Jul-05-2017, 09:18 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  python loop in subprocess vinothkumargomu 6 3,418 Jul-06-2020, 12:02 PM
Last Post: vinothkumargomu
  Python Error in subprocess.py roydianton90 1 5,705 Dec-14-2018, 11:26 AM
Last Post: jeanMichelBain
  OS command via python subprocess module alinaveed786 21 11,525 Oct-23-2018, 05:40 AM
Last Post: alinaveed786
  subprocess in thread python to check reachability anna 3 3,579 Sep-05-2018, 04:01 PM
Last Post: woooee
  Using Subprocess.Popen to start another python script running in background on Window johnb546 0 13,817 Jun-01-2018, 01:57 PM
Last Post: johnb546
  proc communicate not exiting on python subprocess timeout leoonardoo 0 3,896 Sep-13-2017, 09:54 AM
Last Post: leoonardoo
  I have problem on Communication between C++ and Python using subprocess Module hlfan1234567 0 4,324 Jul-09-2017, 04:34 PM
Last Post: hlfan1234567
  Encoding issue while running Sysinternals Autorunsc via Python subprocess JChris 0 3,522 Jun-13-2017, 12:01 AM
Last Post: JChris

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020