User avatar
Protheuz
Posts: 80
Joined: Sat May 11, 2013 5:24 pm
Location: In my chair, bed or sofa.

Python

Sun May 12, 2013 6:56 pm

Hey! Sorry for noobish question, but can i do (for example)
os.system("apt-get update")
then wait until it finished, when its done do
os.system("apt-get upgrade")
wait again, when done do
os.system("apt-get install something")
and so on, i really need to know.

//Protheuz
Wiizard/Protheuz, just call me Kev.

User avatar
rurwin
Forum Moderator
Forum Moderator
Posts: 4205
Joined: Mon Jan 09, 2012 3:16 pm
Contact: Website

Re: Python

Sun May 12, 2013 7:08 pm

Yes you can, but you would have to run Python as root, because apt-get requires root access permissions.

pi@RaspberryPi ~/ $ sudo python

User avatar
davef21370
Posts: 875
Joined: Fri Sep 21, 2012 4:13 pm
Location: Earth But Not Grounded

Re: Python

Mon May 13, 2013 4:58 pm

Would os.system("sudo apt-get whatever") work instead of running as root?

Dave.
Apple say... Monkey do !!

User avatar
rurwin
Forum Moderator
Forum Moderator
Posts: 4205
Joined: Mon Jan 09, 2012 3:16 pm
Contact: Website

Re: Python

Mon May 13, 2013 7:40 pm

Maybe. Try it and see.

But that is sudo by the back-door. If an app needs root privileges I want to know about it and make the decision myself. On a RaspPi it would grab extra privileges silently, which I don't like, but on Ubuntu it would ask for a password, and if it is a GUI app, that would fail.

User avatar
Protheuz
Posts: 80
Joined: Sat May 11, 2013 5:24 pm
Location: In my chair, bed or sofa.

Re: Python

Fri May 24, 2013 7:49 am

I think, if im not wrong, that sudo wont help. It would still open all of the commands at once
Wiizard/Protheuz, just call me Kev.

gkreidl
Posts: 5245
Joined: Thu Jan 26, 2012 1:07 pm
Location: Germany

Re: Python

Fri May 24, 2013 8:39 am

import subprocess

retcode = subprocess.call(["sudo", "apt-get","update"])

and so on ....

subprocess.call() will wait for the commands to finish.
Minimal Kiosk Browser (kweb)
Slim, fast webkit browser with support for audio+video+playlists+youtube+pdf+download
Optional fullscreen kiosk mode and command interface for embedded applications
Includes omxplayerGUI, an X front end for omxplayer

Return to “Python”

Who is online

Users browsing this forum: Google [Bot], joseplaselva, paddyg, SlowBro and 23 guests