0

Through python, is there a way I can open gnome-terminal and then send commands to it, which are then run in that window? For example, where I could do something like

terminal.communicate("echo testing")

and the gnome-terminal prints the output? I've seen similar posts using subprocess Popen and communicate, although I wasn't getting the newly opened terminal to run the commands. Thanks for any help

Shatnerz
  • 2,353
  • 3
  • 27
  • 43
  • This is similar to [this question](http://askubuntu.com/questions/313554/how-to-control-gnome-terminal-from-python-scrypt), which in unanswered. The answered questions only seem to send one command at the start of the gnome-terminal. – Shatnerz Nov 07 '15 at 13:01
  • the answer from the duplicate already handles it: create a named pipe and write the commands to it (how many you like). – jfs Nov 07 '15 at 22:44
  • I guess I'm missing something. I can't get the terminal to run commands from the named pipe – Shatnerz Nov 08 '15 at 01:31
  • "Can't" is not informative. If you don't understand the answers; ask a separate question about the specific aspects of the answer that you have an issue. Make sure to include a minimal code example that demonstrates the issue. Describe in detail what do you expect the code to do and what happens instead (step by step) -- if there are errors; paste them as is in your question. Include the link to the current question for context. – jfs Nov 08 '15 at 02:04

1 Answers1

0

you could do os.system to execute commands, like This

import os
os.system("gnome-terminal -e 'bash -c \"sudo apt-get update; exec bash\"'")
Bharat
  • 287
  • 1
  • 5
  • 14
  • Yes, but there isn't a constant connection there. Say later, I want to automatically run some other command in that specific terminal without having the user type in a command – Shatnerz Nov 07 '15 at 12:53
  • You can always execute multiple commands in a single line using && symbol, for example - sudo apt-get update && sudo apt-get upgrade – Bharat Nov 08 '15 at 16:50
  • Thanks for the follow up. I know of using &&, but I was looking for being able to control the terminal from python, not just start a terminal and run a series of commands. Perhaps I would like to push a command through later on, after some specific event. It was just a thought I had for something I was working on. I will probably just end up running whatever at the opening of the terminal. It gets the job done, but I was just thinking of this to possibly add more functionality later – Shatnerz Nov 08 '15 at 23:51