You are not logged in.

#1 2015-03-03 15:07:13

OKAN
Member
Registered: 2009-01-11
Posts: 28

superuser in python

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

#2 2015-03-03 15:10:01

Alad
Wiki Admin/IRC Op
From: Bagelstan
Registered: 2014-05-04
Posts: 2,420
Website

Re: superuser in python

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

#3 2015-03-03 16:44:52

OKAN
Member
Registered: 2009-01-11
Posts: 28

Re: superuser in python

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 specified

Last edited by OKAN (2015-03-03 16:45:23)

Offline

#4 2015-03-03 16:52:54

satanselbow
Member
Registered: 2011-06-15
Posts: 538

Re: superuser in python

Uh... Oh... pacman GUI alert! We are at DEFCON 5 people... call the opensource pi drone attack cabbages!!!

Offline

#5 2015-03-03 17:03:27

progandy
Member
Registered: 2012-05-17
Posts: 5,279

Re: superuser in python

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

#6 2015-03-04 07:26:16

OKAN
Member
Registered: 2009-01-11
Posts: 28

Re: superuser in python

Thank you all.

Offline

#7 2015-03-05 12:07:38

Mr.Elendig
#archlinux@freenode channel op
From: The intertubes
Registered: 2004-11-07
Posts: 4,094

Re: superuser in python

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

#8 2015-03-06 15:19:49

OKAN
Member
Registered: 2009-01-11
Posts: 28

Re: superuser in python

Thank you @Mr.Elendig. I will work on it.

Offline

Board footer

Powered by FluxBB