我想subprocess.Popen()在Windows中使用rsync.exe,并在Python中打印標(biāo)準(zhǔn)輸出。我的代碼可以運(yùn)行,但是直到文件傳輸完成后才能捕獲進(jìn)度!我想實(shí)時(shí)打印每個(gè)文件的進(jìn)度。因?yàn)槲衣犝f現(xiàn)在應(yīng)該使用Python 3.1,所以它在處理IO方面應(yīng)該更好。import subprocess, time, os, syscmd = "rsync.exe -vaz -P source/ dest/"p, line = True, 'start'p = subprocess.Popen(cmd, shell=True, bufsize=64, stdin=subprocess.PIPE, stderr=subprocess.PIPE, stdout=subprocess.PIPE)for line in p.stdout: print(">>> " + str(line.rstrip())) p.stdout.flush()
從子進(jìn)程實(shí)時(shí)捕獲標(biāo)準(zhǔn)輸出
ibeautiful
2019-10-08 10:09:48