I would like to know how to determine the precise Linux distribution I am on (excluding version numbers), from within a Python script and define a variable as equal to it. Now, I should clarify and say that I have seen these two questions:
and neither one was helpful to me as, the first of these questions had answers that were very generalized and merely returned posix
for all Linux distributions. The second question's answers weren't helpful as I sometimes operate on some more obscure distributions like Manjaro Linux and Sabayon Linux. The most applicable answer to the second question, was platform.linux_distribution()
, which on Manjaro, returns:
('', '', '')
which as you can see is not helpful. Now I know a way I can get half-way to an acceptable answer, as:
from subprocess import call
call(["lsb_release", "-si"])
returns the output (on Manjaro Linux, of course):
ManjaroLinux
0
but defining a variable:
a=call(["lsb_release", "-si"])
gives an a with the value:
>>> a
0
The 'a' is just the exit status, try:
from subprocess import Popen, PIPE, STDOUT
cmd = "lsb_release -si"
p = Popen(cmd, shell=True, stdin=PIPE, stdout=PIPE, stderr=STDOUT, close_fds=True)
output = p.stdout.read()
Replace call with check_output.
from subprocess import check_output
a = check_output(["lsb_release", "-si"])
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With