Python Forum

Full Version: search and store a value from linux command output in to variable python
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi I am a python bigginer, I have a scenario where I need to search and select a particular value from linux command "df -h".

dumpe2fs 1.42.13.x5 (23-Mar-2017)
Inode count: 786432000

In this above output I need to store the inode count number in to a variable to use it for further calculation.
Can anyone explain how to use python regular expressions to do the above task?
Get the output using subprocess.

import subprocess

output = subprocess.run(['df', '-h'], stdout=subprocess.PIPE).stdout
output = output.decode('utf-8')

for line in output.split('\n'):
    if line.startswith('Inode count:'):
        inode_cnt = int(line.split()[1])
Something like that.
Btw, I don't get the number of inodes with df -h.