Monday, May 6, 2024
 Popular · Latest · Hot · Upcoming
1
rated 0 times [  1] [ 0]  / answers: 1 / hits: 1413  / 1 Year ago, thu, december 22, 2022, 5:48:54

I wanted to make a program (with quickly) that edits some root files.



My question:
How can i ask for root permission (after a button is clicked) to execute a command (just like the software center does)?

I want it to be universal. For both gnome and kde


More From » python

 Answers
7

A lot has changed since I asked this question in 2012. These days, pkexec is the preferred way to run things as root, as many desktop environments will implement their own frontend (polkit agent) for it, meaning you won't have to bother with checking for different environments. Additionally, gksudo and kdesudo have been deprecated.


Since python 3.5, the proper way to do this would be:


import subprocess
subprocess.run(["pkexec", "<command>", "<arg1>", "<arg2>"])

[#34802] Friday, December 23, 2022, 1 Year  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
cugure

Total Points: 188
Total Questions: 110
Total Answers: 103

Location: Dominican Republic
Member since Sun, Sep 4, 2022
2 Years ago
;