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
-
Not entirely sure what you're asking. Perhaps you're looking for the subprocess module?David C– David C2016年04月26日 16:21:35 +00:00Commented Apr 26, 2016 at 16:21
2 Answers 2
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.
Comments
To accomplish this, you can use either subprocess or os.system().
Whichever one you use, the bash command to do so would be:
gnome-terminal -e sh /usr/script/update.sh
for subprocess:
import subprocess
subprocess.call(["gnome-terminal", "-x", "sh", "/usr/script/update.sh"])
for 'os.system()'
import os
os.system("gnome-terminal -e "sh /usr/script/update.sh"")
It is recommended you use subprocess.call() for anything more complex than simple commands as os.system() is outdated.
4 Comments
subprocess command I recommended.