paolo zanone paolo zanone - 7 months ago 49
Python Question

Console in new window

I want the commands that run a python file with console
are in an independent window

my code:

def update(self):
self.prombt("sh /usr/script/update.sh")
self.close(None)

def prombt(self, com):
self.session.open(Console,_("sTaRt ShElL cOm: %s") % (com), ["%s" % com])


it's possible?

Tank's

Answer

You can realize this using the subprocess module.

import subprocess

subprocess.call(["gnome-terminal", "-x", "sh", "/usr/script/update.sh"])

In this example I used "gnome-terminal" as my terminal emulator. On your system you may not have this emulator and you should replace it with the one you use (e.g. Konsole for KDE). You must then also find the appropriate parameter (in this case "-x") to execute the command, when opening the emulator.