main.py파이썬, 서브 프로세스에서 입력을 얻으려고합니까?
import subprocess,sys
process = subprocess.Popen([sys.executable]+['example.py'], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
while True:
out = process.stdout.read(1)
if not out:
out=process.stderr.read(1)
if out == '' and process.poll() != None:
break
if out != '':
print out
example.py
f=raw_input('WHats your favorite animal')
내가 내 메인 루프에 입력을 확인하고 일부 데이터를 제공 할 수있는 방법을 궁금해하고 확인을 클릭합니다. 지금 raw_input을 사용할 때 프로그램이 멈 춥니 다. 여기
내가 이런 기능이 있는지 잘 모릅니다
while True:
out = process.stdout.read(1)
if not out:
out=process.stderr.read(1)
if out == '' and process.poll() != None:
break
#showing what i want
if request_input==True:
give_input('cat') #Give input to the raw_input
#
if out != '':
print out
을하고 싶은 것입니다. 더 자세한 설명이 필요하면 의견을 말하십시오.
관련 : http://stackoverflow.com/questions/375427/non-blocking-read-on-a
여기당신을 위해 pexpect-example.py 찾고있다 -subprocess-pipe-in-python – ChristopheD
나는 이것을 사용하기 위해서 C++을 사용하기까지한다. IDLE.py는 어떻게 작동합니까? – user1357159