Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

I am developing an application in PyGtk, and would like to launch a gnome-terminal and output commands to it.

My user should then be able to modify the command, or maybe ignore using the up arrow ... etc.

I have been able to launch a terminal, but can't work out how to send commands.

This is how my application starts:

class App(Gtk.Window):

    def __init__(self):

        Gtk.Window.__init__(self)

        process=subprocess.Popen(["gnome-terminal", "--class=App", "--name=app"], shell=False, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
        response,error=process.communicate()
share|improve this question

1 Answer 1

According to the python docs, you want to use Popen.communicate(input=None) http://docs.python.org/2/library/subprocess.html#popen-objects

I would recommend that you edit your command from python before sending it to another process. For example, display a window with the default command and allow the user to edit (or cancel) it before executing it. Also, "gnome-terminal" is probably overkill for this, "/bin/bash" should be sufficient.

If that doesn't work for you, you could also try this. (depending on what you are actually running from the terminal) Since you mentioned users could edit the command, it would be a good idea to validate the input before running.

command = ['ls','-l']
output = subprocess.check_output( command )
print( output )
share|improve this answer
1  
OP is already using the suggestion via response,error=process.communicate() where process is an instance of Popen. "Also, "gnome-terminal" is probably overkill for this, "/bin/bash" should be sufficient." I think OP actually deliberately wants to show the terminal in his GUI app. –  gertvdijk Jun 27 '13 at 22:40
    
You are correct @gertvdijk, I want a terminal embedded into my application. I am currently using Vte.Terminal, which is good, but it does not behave just like gnome-terminal. For example the delete key produces ^[[3~, and the up arrow key does not show the previous command. I also got excited by what I found here: "gnome-terminal --help-gtk", and figured this would do the job. –  Anthony Scaife Jun 30 '13 at 0:31
    
@user936401 If you did found the solution, please create a new answer. –  Lucio Jul 11 '13 at 23:09

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.