Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Starting gnome-terminal with arguments

Using Python , I would like to start a process in a new terminal window, because so as to show the user what is happening and since there are more than one processes involved.

I tried doing:

>>> import subprocess
>>> subprocess.Popen(['gnome-terminal'])
<subprocess.Popen object at 0xb76a49ac>

and this works as I want, a new window is opened.

But how do I pass arguments to this? Like, when the terminal starts, I want it to say, run ls. But this:

>>> subprocess.Popen(['gnome-terminal', 'ls'])
<subprocess.Popen object at 0xb76a706c>

This again works, but the ls command doesn't: a blank terminal window starts.

So my question is, how do I start the terminal window with a command specified, so that the command runs when the window opens.

PS: I am targetting only Linux.

like image 369
user225312 Avatar asked Dec 22 '22 19:12

user225312


1 Answers

$ gnome-terminal --help-all

 ...

  -e, --command                   Execute the argument to this option inside the terminal

 ...

If you want the window to stay open then you'll need to run a shell or command that keeps it open afterwards.

like image 102
Ignacio Vazquez-Abrams Avatar answered Jan 08 '23 01:01

Ignacio Vazquez-Abrams