Python Forum
gnome terminal playing with python
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
gnome terminal playing with python
#1
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
1
2
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
Reply
#2
better use Popen

from subprocess import Popen

1
Popen["gnome-terminal", "-e", "'python3 /path/to/pyFoamRunner.py'"]
Reply
#3
facing an error stating

Quote:TypeError: 'type' object is not subscriptable
Reply
#4
forgot brackets

1
Popen(["gnome-terminal", "-e", "python3 '/path/to/pyFoamRunner.py'"])
Reply
#5
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.
Reply
#6
try changing working dir to path of scrpipt

change path to the path of pyFoamRunner.py

1
2
3
4
5
import os
from subprocess import Popen
 
os.chdir(path)
Popen(["gnome-terminal", "-e", "python3 ./pyFoamRunner.py"])
Reply
#7
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.
Reply
#8
I think there is something wrong with your paths

I've created a test.py in /tmp

then

1
2
3
4
5
import os
from subprocess import Popen
  
os.chdir("/tmp")
Popen(["xfce4-terminal", "-e", "python3 ./test.py"])
and it works as expected.
Reply
#9
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.
Reply
#10
Then is it an installed module? You never mentioned that.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  updating pip, python - understanding terminal and pycharm. endlessnameless 0 1,242 Jun-24-2024, 05:48 AM
Last Post: endlessnameless
  gnome-terminal Raysz 5 1,636 May-11-2024, 10:25 AM
Last Post: snippsat
  invoking python in Terminal Euler 2 1,287 Aug-25-2023, 06:17 AM
Last Post: perfringo
  Launch Python IDLE Shell from terminal Pavel_47 5 2,682 Feb-17-2023, 02:53 PM
Last Post: Pavel_47
  Python VS Code: using print command twice but not getting output from terminal kdx264 4 2,169 Jan-16-2023, 07:38 PM
Last Post: Skaperen
  Dynamic Printing With Python Terminal MrTim 2 4,342 Jul-06-2021, 04:00 PM
Last Post: MrTim
  Running latest Python version on the Terminal (MAC) Damian 4 3,699 Mar-22-2021, 07:58 AM
Last Post: Damian
  keyboard module doesn't work in the microsoft version terminal of python. username 1 4,035 Feb-25-2021, 05:19 PM
Last Post: Larz60+
  Refresh data in python script while running in Terminal frankenchrist 4 11,810 Feb-03-2021, 09:54 AM
Last Post: Larz60+
  .wav file not playing in python .exe program ose 0 3,167 Jun-24-2020, 07:17 PM
Last Post: ose

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020