我在macossierra上使用python2.7.10,并用我的raspberrypi创建了一个rsync over ssh连接。这个想法是在raspberrypi上同步本地文件夹和远程文件夹。在
我的函数syncroFolder()工作正常,但如何在tkinter窗口上显示实时状态?有什么简单的解决办法吗?我无法理解发布的问题:“将命令行结果重定向到tkinter GUI”
def syncroFolder():
os.system("rsync -avz -e \"ssh -p port\" /source/path /folder/to/rcync ")
谢谢你的帮助
2017年9月5日: 我设法用“| tee”把结果写到一个文件中,我的命令现在是这样的
^{pr2}$我在TKinter中创建了一个显示文件最后一行的文本框
status, lastLineInFile = commands.getstatusoutput("tail -n 1 "+ exampleOutputTxtAdd)
T.insert(END,'Transfering: \n'+lastLineInFile)
输出文件如下所示:
sending incremental file list
folder/
0 0% 0.00kB/s 0:00:00 (xfr#0, to-chk=397/410)
folder/Bigfile.avi
32,768 0% 0.00kB/s 0:00:00
2,555,904 0% 2.39MB/s 0:07:18
3,112,960 0% 1.41MB/s 0:12:23
3,637,248 0% 1.11MB/s 0:15:44
但是文本框显示了所有这些行
Transfering
3,776 0% 0.00kB/s 0:00:00
16,567,040 1% 13.69MB/s 0:01:15
并继续添加行,即使我读取了输出文件的-n=1行。在
我一直在尝试使用--out格式=\“%t%o%f%b\”,但只有在传输后才有状态(如果是大文件)。。。我尝试了很多选择,但没有一个对我有效。。。我不明白为什么它不只显示输出文件的最后一行。 你有什么建议吗?在
这里有一个使用python3的例子(因为我有这个例子)。其本质与引用示例中一样,使用线程将管道逐行读入队列,然后使用after事件读取队列。增强将是每次从队列中读取所有项,并在子进程停止后停止事件序列。使用
python3 tkinter_rsync.py rsync://servername/sharename
或类似的方法进行测试。在相关问题 更多 >
编程相关推荐