내 코드는 다음과 같습니다. 기본적으로이 모듈은 필요한 명령을 실행하고 줄 바꿈을 캡처하지만 내 경우에는 명령이 실행될 때 명령 프롬프트로 돌아 가기 위해 몇 초가 걸립니다. thats where child.stdout.read (1)이 멈추고,이 명령을 사용하여 정상적인 명령을 실행하면 예상대로 모든 것이 인쇄됩니다. 하지만 명령을 인쇄 STDOUT에 뭔가를해야만하고 프롬프트로 돌아가려면 시간이 좀 걸립니다, 특별한 경우에, 그것은 중단 .. 도와주세요파이썬 STDOUT 실시간 읽기
새로운 코드 :
def run_command(shell_command):
'''run the required command and print the log'''
child = subprocess.Popen(shell_command, shell=True,stdout=subprocess.PIPE)
(stdoutdata, stderrdata) = child.communicate()
print stdoutdata
print "Exiting.."
오류 :
File "upgrade_cloud.py", line 62, in <module>
stop_cloud()
File "upgrade_cloud.py", line 49, in stop_cloud
run_command(shell_command)
File "upgrade_cloud.py", line 33, in run_command
(stdoutdata, stderrdata) = child.communicate()
File "/usr/lib/python2.6/subprocess.py", line 693, in communicate
stdout = self.stdout.read()
KeyboardInterrupt
child.wait()
이 줄은 자식 시저를 기다리는 파이썬 원인 :
음 ...이 문제는 [issue 7213] (http://bugs.python.org/issue7213) 일 수 있습니다. 동시에 여러 개의 Popen 인스턴스를 실행하고 있습니까? – Kevin
아니요, 한 번에 하나의 명령 만 실행하고 나옵니다. –
제발 도와주세요, 나는이 문제에 붙어있다 –