0
위의 코드는 코드 실행이 완료된 경우에만 rsync 진행률을 보여줍니다. 나는 그것이 진행되는대로 진전을 인쇄하고 싶다. 예를 들어 파일 전송 중일 때 진행 상황을 모두 보여주고 싶습니다. 어떻게해야합니까?하위 프로세스가 실행 중일 때이 코드의 진행률을 인쇄하는 방법은 무엇입니까?
import re
import subprocess
def sort(rprogress):
'''This function extracts the percentage from the rsync progress and return strings of percentanges'''
progress1 = re.findall(r'\d+%', rprogress)
remove_duplicate = set(progress1) #Remove Duplicate percentage from list
remove_percent = [a.replace('%', '') for a in remove_duplicate] #Removes percentage
sorted_list = sorted(remove_percent, key=int) #Sort in ascending order
#result = ', '.join(map(lambda sorted_list: str(sorted_list) + '%', sorted_list)) #Adds the percentage
return sorted_list
source12 = '[email protected]:/home/sachet/my_files/ok.txt'
password = 'password'
destination = '/home/zurelsoft/files'
result = subprocess.Popen(['sshpass', '-p', password, 'rsync', '-avz', '--info=progress2', source12, destination],
stdout=subprocess.PIPE).communicate()[0]
print result
print sort(result)