Python Forum

Full Version: read terminal text from running program
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
i have a requirement to run badblocks on a raspberry pi checking a usb stick. this is not my requirement so please don't advise to change this as i cant do that.

what i would like help with is to run a python script that runs badblocks and can either monitor the text on the screen for progression reasons or write the information to a text file where i can read it at any point. i dont need help with reading the file as i can do this already.

i can create a script to run it locally or run it remotely but i am unable to pragmatically get the progress (it takes about 1 hour to complete the task)

i have tried a simple redirect >> to a file but this is no good as i ether get an empty file or it does nothing at all.
below is the command and i want to continuously or on demand get the percentage and or errors using python.

sudo badblocks -swv -t 0XAA /dev/sda1
Checking for bad blocks in read-write mode
From block 0 to 60088303
Testing with pattern 0xaa: 28.62% done, 19:38 elapsed. (0/0/0 errors)

i don't have any code to share because i don't know where to start on this so would appreciate any help anyone can give me.
man badblocks shows that there is a -o output_file switch. Have you tried that?
yes -o creates a file with any bad blocks it finds, good spot but not what i am after. because most of the time no bad blocks will be found the file is just empty, also this does not give me the current progress. but thanks anyway