Detect Linux Runlevel
lew.pitcher at digitalfreehold.ca
Mon Dec 5 16:38:00 EST 2016
On Monday December 5 2016 16:25, in comp.lang.python, "DFS" <nospam at dfs.com>
> On 12/05/2016 03:58 PM, Wildman wrote:
>> I there a way to detect what the Linux runlevel is from
>> within a Python program? I would like to be able to do
>> it without the use of an external program such as 'who'
>> or 'runlevel'.
> Why not?
> '>>> import os
> '>>> os.system("systemctl get-default")
$ cat rlevel.py
16:36 $ python rlevel.py
sh: systemctl: command not found
> systemd 'graphical.target' corresponds to the old runlevel 5.
The OP asked for the runlevel, not the systemd target.
"In Skills, We Trust"
PGP public key available upon request
More information about the Python-list