Issue
I'm trying to make a python script that would clone(ISO image) one usb stick to another using dd if=/dev/sda of=/dev/sdb
Here's my problem: I want to create progress bar showing what is done.
I tried:
- Looking at storage space at second usb stick, but this doesn't work beacause ISO image scans also unused space
- By adding
status=progress
todd
command I can get progress in terminal but I can't figure how to access stdout from python. I triedsubprocess.Popen,run(stdout = PIPE)
with and withoutshell = True
readingprocess.stdout
with.read()
,.read(1)
,.readline()
orcommunicate()
. Nothing worked for me. (https://www.endpointdev.com/blog/2015/01/getting-realtime-output-using-python/)
I can see progress going on in python shell but .read()
function always get stuck.
Part of code I am concerned about:
comm = 'sudo dd if=/dev/sda of=/dev/sdb'
cloning = subprocess.Popen(shlex.split(comm),stdout = PIPE,text = True)
while True:
print(cloning.stdout.read())
I want something that would work like:
while True:
progress = cloning.stdout.read()
update_bar(progress)
I'm using python 3.7 on Raspberry
Thanks for help
Solution
You were on the right track with status=progress
, but it outputs to stderr, not stdout. If you do stderr = PIPE
and then read from cloning.stderr
instead of cloning.stdout
, it will work.
Answered By - Joseph Sible-Reinstate Monica
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.