How do I execute a command when a button is clicked?

Asked by Charles Edward Pax

Quoted from an entry in Question #17550:

i have succesfully created a button in glade, called dcdbas...added the signal, and ran it through gladex...
as you can see below, i can print out a message, and i see the message in a terminal when i press the button, so thats ok i think...

def on_dcdbas_clicked(widget, data, wtree):
 print "Modprobing dcdbas..."
 pass

now my question, so i can print a message when i press the button, but it also needs to execute a command when i press it: (gk)sudo modprobe dcdbas
how does this work?

thanks in advance!

Question information

Language:
English Edit question
Status:
Solved
For:
Gladex Edit question
Assignee:
No assignee Edit question
Solved by:
Charles Edward Pax
Solved:
Last query:
Last reply:
Revision history for this message
Charles Edward Pax (pax) said :
#1

Quoted from a response in Question #17550:
I often use:
import commands

a = commands.getoutput("echo 'hello' ")

print a

the output will be:
'hello'

the more offical way to run a command is:

import os

os.system("echo 'hello'")

though I am unsure how you get the stdout of the message. so I use the former.

I hope this answers your question.