에서 표준 입력 입력을받을 수 없습니다서브 프로세스 내가 가진 <code>repeat.py</code> 파일 편집</p> <p>나는 두 과정 사이 <code>subprocess</code> 교환 데이터를 사용하는 다른 공정
이 파일은 http://www.doughellmann.com/PyMOTW/subprocess/
import sys
sys.stderr.write('repeater.py: starting\n')
sys.stderr.flush()
while True:
next_line = sys.stdin.readline()
if not next_line:
break
sys.stdout.write(next_line)
sys.stdout.flush()
sys.stderr.write('repeater.py: exiting\n')
sys.stderr.flush()
에서 예이다
이 파일을 실행하여 ipython
In [1]: import subprocess
In [2]: f=subprocess.Popen(['python','~/repeat.py'],shell=True,stdin=subprocess.PIPE,stdout=subprocess.PIPE)
In [3]: f.stdin.write('teststs\n')
In [4]: f.communicate()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
NameError: name 'teststs' is not defined
Out[4]: ('', None)
teststs
이 정의되지 않은 이유는 무엇입니까?
@Sven Marnach가 귀하의 의견을 보내 주셔서 감사합니다.'shell = True'를 제거한 후 괜찮습니다. – timger
괜찮 았음 - 답변을 답글로 바꾸 었습니다. –
related : [subprocess 'docs]에서 shell = True와 함께 list 인수를 사용하지 마십시오 (http://bugs.python.org/issue21347) – jfs