Hello everyone,
Hope you are fine and safe!
I have started learning and i want to play with gnome-terminal using python3 in ubuntu. I have googled and found a simple code using
import os
os.system("gnome-terminal -e 'sudo apt-get update'")
Actually I want to run a python program named 'pyFoamRunner.py' in gnome-ternimal.
Any idea how can i perform that?
Thanks,
Jmex
better use Popen
from subprocess import Popen
Popen["gnome-terminal", "-e", "'python3 /path/to/pyFoamRunner.py'"]
facing an error stating
Quote:TypeError: 'type' object is not subscriptable
forgot brackets
Popen(["gnome-terminal", "-e", "python3 '/path/to/pyFoamRunner.py'"])
Thanks for helping, it runs without any error but doesn't seem to work the way it should. It creates many files in the working folder if it is made to run with gnome-terminal but if I am running with the code, it doesn't make any file.
try changing working dir to path of scrpipt
change
path to the path of pyFoamRunner.py
import os
from subprocess import Popen
os.chdir(path)
Popen(["gnome-terminal", "-e", "python3 ./pyFoamRunner.py"])
nope, nothing. same happens, it runs the code but doesn't execute.
There is no file named pyFoamRunner.py in that folder, but when i execute that command in the terminal in that folder, it will create few files automatically.
But it doesn't happen with python.
I think there is something wrong with your paths
I've created a test.py in /tmp
then
import os
from subprocess import Popen
os.chdir("/tmp")
Popen(["xfce4-terminal", "-e", "python3 ./test.py"])
and it works as expected.
no problem with my path i guess. Like you have a python file named test.py in the folder, i do not have such file named pyFoamRunner.py. But when i use to give command in terminal, 'pyFoamRunner.py .' with a dot at the end, it creates many files in that particular folder even though that file(pyFoamRunner.py) isn't in the folder.
Then is it an installed module? You never mentioned that.