Python Forum
read terminal text from running program
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
read terminal text from running program
#1
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.
Reply
#2
man badblocks shows that there is a -o output_file switch. Have you tried that?
Reply
#3
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
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Program running on RPi 3b+ Very Strange Behavior - Out of Bound Index MadMacks 26 3,278 Mar-07-2023, 09:50 PM
Last Post: MadMacks
  googletrans library to translate text language for using data frame is not running gcozba2023 0 1,223 Mar-06-2023, 09:50 AM
Last Post: gcozba2023
  Read text file, modify it then write back Pavel_47 5 1,588 Feb-18-2023, 02:49 PM
Last Post: deanhystad
  read a text file, find all integers, append to list oldtrafford 12 3,517 Aug-11-2022, 08:23 AM
Last Post: Pedroski55
  running a TensorFlow program Led_Zeppelin 0 907 Apr-07-2022, 06:33 PM
Last Post: Led_Zeppelin
  saving and loading text from the clipboard with python program MaartenRo 2 1,656 Jan-22-2022, 05:04 AM
Last Post: MaartenRo
  Not able to read the text using pexpect/expect Bipinjohnson 7 4,031 Jan-10-2022, 11:21 AM
Last Post: Bipinjohnson
  [SOLVED] Read text file from some point till EOF? Winfried 1 1,950 Oct-10-2021, 10:29 PM
Last Post: Winfried
  Open and read multiple text files and match words kozaizsvemira 3 6,737 Jul-07-2021, 11:27 AM
Last Post: Larz60+
  Running latest Python version on the Terminal (MAC) Damian 4 2,639 Mar-22-2021, 07:58 AM
Last Post: Damian

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020