2016-06-07 1 views

Antwort

1

Es gibt so viele Möglichkeiten, eine Schleife zu schreiben. Ich mag:

yes | sed 5q | while read r; do sleep 1; printf .; done; echo 

Aber Sie wollen wirklich keine Schleife; Sie wollen, bis die Kopie beendet das Drucken der Fortschrittsbalken zu halten, so dass Sie wollen so etwas wie:

progress() { while :; do sleep 1; printf .; done; } 

copy_the_files & # start the copy 
copy_pid=$!  # record the pid 
progress &  # start up a process to draw the progress bar 
progress_pid=$! # record the pid 
wait $copy_pid # wait for the copy to finish 
kill $progress_pid # terminate the progress bar 
echo 

oder vielleicht (wo man den Schlaf 5 'mit Befehlen ersetzen sollten Ihre Dateien kopieren)

#!/bin/bash 

copy_the_files() { sleep 5; kill -s USR1 $$; } 
progress() { while :; do sleep 1; printf .; done; } 
copy_the_files & 
progress & 
trap 'kill $!; echo' USR1 
wait 
0

Es kann Ihnen helfen!

import time 

print "Copying files .." 
time.sleep(1) 
print "." 
time.sleep(1) 
print "." 
time.sleep(1) 
print ".." 
time.sleep(1) 
print "" 
print "File copy complete" 
1

In Python können Sie etwas tun:

from time import sleep 
from sys import stdout 

Print = stdout.write 
Print("Copying files..") 
for x in xrange(4): 
    Print(".") 
    sleep(1) 
print "\nFile copy complete." 

Bei jeder Iteration druckt er eine neue .

Nach einer schnellen Suche fand ich diese article, die eine gute Erklärung dafür gibt, wie man eine Datei/ein Verzeichnis kopiert, während ein Fortschrittsbalken aktualisiert wird.

Verwandte Themen