You are not logged in.
Pages: 1
Hi,
I am a newbie in python and I have a question: How can I run a linux system command as a superuser, using a python script?
Offline
Google for "python os system sudo".
or do "sudo ./script.py"
edit: or even better yet, exactly describe what you're trying to do.
Last edited by Alad (2015-03-03 15:14:53)
Mods are just community members who have the occasionally necessary option to move threads around and edit posts. -- Trilby
Offline
Actually I have a basic code:
import os
import sys
from PyQt4.QtCore import *
from PyQt4.QtGui import *
 
def main():
    app = QApplication(sys.argv)
    w = MyWindow()
    w.show()
    sys.exit(app.exec_())
 
class MyWindow(QWidget):
    def __init__(self, *args):
        QWidget.__init__(self, *args)
        self.le = QLineEdit()
        self.te = QTextEdit()
        layout = QVBoxLayout(self)
        layout.addWidget(self.le)
        layout.addWidget(self.te)
        self.setLayout(layout)
        self.connect(self.le, SIGNAL("returnPressed(void)"), self.komut_calistir)
    def komut_calistir(self):
        komut = str(self.le.text())
        cikti = os.popen4(komut)[1].read()
        self.te.setText(cikti)
 
if __name__ == "__main__":
    main()When I tried "pacman -Syu", got an error:
sudo: no tty present and no askpass program specifiedLast edited by OKAN (2015-03-03 16:45:23)
Offline
Uh... Oh... pacman GUI alert! We are at DEFCON 5 people... call the opensource pi drone attack cabbages!!!
Offline
Since you have a GUI, you should use a graphical sudo replacement, like e.g. kdesu, gksu, gtksu, ktsuss, ...
Alternatively you can run sudo in askpass-mode (sudo -A) and set the environment variable SUDO_ASKPASS to a valid SSH_ASKPASS application, e.g. openssh-askpass
| alias CUTF='LANG=en_XX.UTF-8@POSIX ' |
Offline
Thank you all.
Offline
1. https://projects.archlinux.org/users/remy/pyalpm.git/
2. *never* use os.(p)open*, use the subprocess module
Evil #archlinux@libera.chat channel op and general support dude.
. files on github, Screenshots, Random pics and the rest
Offline
Thank you @Mr.Elendig. I will work on it.
Offline
Pages: 1