2010-07-09 5 views
12

paramiko를 사용하여 원격 Linux 시스템에서 쉘 스크립트를 시작합니다. 쉘 스크립트가 실행되고 make -j8 명령이 실행됩니다. 그러나 exec_command는 make가 완료되기 전에 반환됩니다.paramiko SSH exec_command (쉘 스크립트)가 완료 전에 반환됩니다.

로컬 컴퓨터에서 스크립트를 실행하면 올바르게 실행됩니다.

누군가이 동작을 설명 할 수 있습니까?

답변

21

응용 프로그램이 끝날 때까지 기다려야합니다. exec_command는 차단 호출이 아닙니다.

print now(), "before call" 
stdin, stdout, sterr = ssh.exec_command("sleep(10)") 
print now(), "after call" 
channel = stdout.channel 
print now(), "before status" 
status = channel.recv_exit_status() 
print now(), "after status" 
+2

now() 님의 목적은 무엇입니까? 서로 빨리 끝내 버리는 것 같아요? 응용 프로그램이 끝날 때까지 기다리라고 하시겠습니까? while channel.recv_exit_status() : 'wait while while while? 그렇다면 recv_exit_status()가 True를 반환하면 stdout에 데이터가있을 경우 stdout.channel.recv_ready()가 True인지 보장합니까? 때로는 이것이 사실이 아닌 것처럼 보입니다. –

+1

이 동작은 문서화되어 있습니다 [here] (http://paramiko-docs.readthedocs.org/en/latest/api/channel.html#paramiko.channel.Channel.recv_exit_status) – miraculixx

+0

stdout.channel.recv_exit_status()를 사용하여 이상하게, 내 코드를 영원히 차단합니다. –

관련 문제