Answer the question
In order to leave comments, you need to log in
How to properly execute lsblk command via python on Linux?
Good afternoon!
I'm trying to execute the lsblk linux command and output them (stdout). Everything is output except for the FSTYPE column. I do not understand why the data from this column is not displayed.
import sys
import subprocess
f = open('text.txt', 'r')
stdout_file = sys.stdout
stdout_file.write(f.read())
x = 'nvme0n1'
Y = subprocess.run(['lsblk', '-o', 'NAME,FSTYPE,SIZE,TYPE,MOUNTPOINT', '-l'], stdout=subprocess.PIPE, encoding='utf-8').stdout
print(Y)
print(type(Y))
NAME FSTYPE SIZE TYPE MOUNTPOINT
nvme0n1 476,9G disk
nvme0n1p1 512M part
nvme0n1p2 476,4G part /run/host/share/icons
Answer the question
In order to leave comments, you need to log in
I don't know why, but isn't it easier to run with a key -J
to get JSON?!
lsblk -o NAME,FSTYPE,SIZE,TYPE,MOUNTPOINT -l -J
{
"blockdevices": [
{"name":"loop0", "fstype":"squashfs", "size":"9.1M", "type":"loop", "mountpoint":"/snap/canonical-livepatch/95"},
{"name":"loop1", "fstype":"squashfs", "size":"91.3M", "type":"loop", "mountpoint":"/snap/go/7165"},
{"name":"loop3", "fstype":"squashfs", "size":"99.2M", "type":"loop", "mountpoint":"/snap/core/10859"},
...
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question