am using debian lenny and tried to create a shutdwon script using python
os.system("sudo shutdown -h now")
i cant use this in debian lenny then how will i implement
i cant use this in debian lenny
I don't understand why you can't use this. Also, you probably only want root access for the script, otherwise anyone can shut down your system. If you want to run it from a non-root user, then you or the program will also have to be able to supply the correct password, which also is a bad idea.
Edited 6 Years Ago by woooee: n/a
Could you be more descriptive than "I can't use this"? Do you get an error? Does it just not do anything in general?
As you probably know, you need elevated privileges to run a command with "sudo," so my guess is that you need to run your script with "sudo":
sudo python MyScript.py
this is working if am going through terminal but here am using a gui so after running the script its not promting for password and its not getting shutdown
msgbox("You chose to Shutdown")
msg = "Do you want to schedule your Shutdown"
title = "Confirmation"
t=integerbox('Enter the time in minutes :')
#os.system('sudo shutdown -h now')
commands.getoutput('sudo shutdown -r now')
os.system('sudo shutdown -h now')
You can or at least used to be able to shutdown in python using python dbus Hal.
The following works in Slackware 13 Mandriva and Fedora.
import dbus bus = dbus.SystemBus() shut = bus.get_object('org.freedesktop.Hal', '/org/freedesktop/Hal/devices/computer') shutr = dbus.Interface(shut , 'org.freedesktop.Hal.Device.SystemPowerManagement') shutr.Shutdown()
But dbus is a can of worms and constantly changing giving us in linux all the joys of the Windows registry. So in ubuntu 10.10 hal has disappeared and UPower has appeared at least in the default installation. I can no longer shutdown but with UPower I can Hibernate or Suspend. The following works in Ubuntu 10.10 for me (of course some hardware setups have problems with hibernate).
import dbus bus = dbus.SystemBus() shut = bus.get_object('org.freedesktop.UPower', '/org/freedesktop/UPower') shutr = dbus.Interface(shut , 'org.freedesktop.UPower') shutr.Hibernate()
To just use halt or shutdown explore sudo -A and SUDO_ASKPASS
with say a simple little pygtk or pyqt dialog to get the password.
Hi. so this is actually a continuation from another question of mineHere but i was advised to start a new thread as the original question was already answered.
This is the result of previous question answered :
code for the listbox - datagridview interaction
At the top of the code ...
Hi. I have a form with list box : lst_product, datagridview : grd_order and button: btn_addline. lst_product has a list of product ids selected from database (MS Acess 2013) , grd_order is by default empty except for 2 headers and btn_addline adds rows to grd_order.
Private Sub btn_addline_Click(ByVal ...
OK, so HostGator for some reason no longer allows gcc/g++ access unless you have a Designated Server account, which is a lot of money to spend just to compile my "Hello World" program. Thus I figured I'd compile at home, then upload. Program is your regular old bare-bones Hello World ...