How to control gnome-terminal from Python scrypt?How to send terminal command to a TTY terminalWhy do most GNOME developers prefer Python over Java for GTK+ programming?Why can't I import “pygtk” with Python 3.2 from PyDev?How to dynamically get name, version and other info from a Python app at runtimeHow install GTK+ 3 for PythonUbuntu Touch - how to create Unity .desktop launcher to make UT terminal to open and execute a command?Python NameError: global name 'resolution' is not definedhow do I create gnome-terminal from python code?Running Ubuntu Touch applications in command line for gdb debugging?Cron task stops performing when encounters unredirected stdout/stderrGnone-Wayland: Does launching a pkexec prompt from an X11 terminal (ex terminology in xwayland) result in a X11 pkexec prompt?

How can we have a quark condensate without a quark potential?

Is Manda another name for Saturn (Shani)?

Brexit - No Deal Rejection

Violin - Can double stops be played when the strings are not next to each other?

Why does a Star of David appear at a rally with Francisco Franco?

Why do passenger jet manufacturers design their planes with stall prevention systems?

If I can solve Sudoku, can I solve the Travelling Salesman Problem (TSP)? If so, how?

When to use a slotted vs. solid turner?

Simplify an interface for flexibly applying rules to periods of time

Could this Scherzo by Beethoven be considered to be a fugue?

PTIJ: Halachic Status of Breadboards on Pesach

How to get the n-th line after a grepped one?

Could the Saturn V actually have launched astronauts around Venus?

Are all passive ability checks floors for active ability checks?

PTIJ: Who should I vote for? (21st Knesset Edition)

Most cost effective thermostat setting: consistent temperature vs. lowest temperature possible

How to make healing in an exploration game interesting

Professor being mistaken for a grad student

What is the meaning of まっちろけ?

Instead of a Universal Basic Income program, why not implement a "Universal Basic Needs" program?

What are substitutions for coconut in curry?

How to explain that I do not want to visit a country due to personal safety concern?

Why is a white electrical wire connected to 2 black wires?

Python if-else code style for reduced code for rounding floats



How to control gnome-terminal from Python scrypt?


How to send terminal command to a TTY terminalWhy do most GNOME developers prefer Python over Java for GTK+ programming?Why can't I import “pygtk” with Python 3.2 from PyDev?How to dynamically get name, version and other info from a Python app at runtimeHow install GTK+ 3 for PythonUbuntu Touch - how to create Unity .desktop launcher to make UT terminal to open and execute a command?Python NameError: global name 'resolution' is not definedhow do I create gnome-terminal from python code?Running Ubuntu Touch applications in command line for gdb debugging?Cron task stops performing when encounters unredirected stdout/stderrGnone-Wayland: Does launching a pkexec prompt from an X11 terminal (ex terminology in xwayland) result in a X11 pkexec prompt?













5















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
















bumped to the homepage by Community 16 mins ago


This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.















  • related Stack Overflow question

    – jfs
    Nov 7 '15 at 22:48















5















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
















bumped to the homepage by Community 16 mins ago


This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.















  • related Stack Overflow question

    – jfs
    Nov 7 '15 at 22:48













5












5








5


0






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
















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()






command-line application-development python gnome-terminal gtk






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Jun 27 '13 at 21:56









Lucio

12.6k2485161




12.6k2485161










asked Jun 27 '13 at 21:26









Anthony ScaifeAnthony Scaife

13616




13616





bumped to the homepage by Community 16 mins ago


This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.







bumped to the homepage by Community 16 mins ago


This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.














  • related Stack Overflow question

    – jfs
    Nov 7 '15 at 22:48

















  • related Stack Overflow question

    – jfs
    Nov 7 '15 at 22:48
















related Stack Overflow question

– jfs
Nov 7 '15 at 22:48





related Stack Overflow question

– jfs
Nov 7 '15 at 22:48










2 Answers
2






active

oldest

votes


















0














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




















  • 2





    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











  • No solution found.

    – Anthony Scaife
    Dec 10 '14 at 10:16


















0














I had the same problem.



Solved it with tmux, thanks to this answer (copied below).



In the terminal that should receive the command start tmux with an identifier:



tmux new-session -s MYSES


Send commands to it with:



tmux send-keys -t MYSES "ls -l"$'n'





share|improve this answer
























    Your Answer








    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "89"
    ;
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function()
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled)
    StackExchange.using("snippets", function()
    createEditor();
    );

    else
    createEditor();

    );

    function createEditor()
    StackExchange.prepareEditor(
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader:
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    ,
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );













    draft saved

    draft discarded


















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f313554%2fhow-to-control-gnome-terminal-from-python-scrypt%23new-answer', 'question_page');

    );

    Post as a guest















    Required, but never shown

























    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0














    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




















    • 2





      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











    • No solution found.

      – Anthony Scaife
      Dec 10 '14 at 10:16















    0














    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




















    • 2





      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











    • No solution found.

      – Anthony Scaife
      Dec 10 '14 at 10:16













    0












    0








    0







    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















    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














    share|improve this answer



    share|improve this answer








    edited Jun 28 '13 at 0:25

























    answered Jun 27 '13 at 22:37









    DavidDavid

    212




    212







    • 2





      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











    • No solution found.

      – Anthony Scaife
      Dec 10 '14 at 10:16












    • 2





      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











    • No solution found.

      – Anthony Scaife
      Dec 10 '14 at 10:16







    2




    2





    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






    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





    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





    @user936401 If you did found the solution, please create a new answer.

    – Lucio
    Jul 11 '13 at 23:09













    No solution found.

    – Anthony Scaife
    Dec 10 '14 at 10:16





    No solution found.

    – Anthony Scaife
    Dec 10 '14 at 10:16













    0














    I had the same problem.



    Solved it with tmux, thanks to this answer (copied below).



    In the terminal that should receive the command start tmux with an identifier:



    tmux new-session -s MYSES


    Send commands to it with:



    tmux send-keys -t MYSES "ls -l"$'n'





    share|improve this answer





























      0














      I had the same problem.



      Solved it with tmux, thanks to this answer (copied below).



      In the terminal that should receive the command start tmux with an identifier:



      tmux new-session -s MYSES


      Send commands to it with:



      tmux send-keys -t MYSES "ls -l"$'n'





      share|improve this answer



























        0












        0








        0







        I had the same problem.



        Solved it with tmux, thanks to this answer (copied below).



        In the terminal that should receive the command start tmux with an identifier:



        tmux new-session -s MYSES


        Send commands to it with:



        tmux send-keys -t MYSES "ls -l"$'n'





        share|improve this answer















        I had the same problem.



        Solved it with tmux, thanks to this answer (copied below).



        In the terminal that should receive the command start tmux with an identifier:



        tmux new-session -s MYSES


        Send commands to it with:



        tmux send-keys -t MYSES "ls -l"$'n'






        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited Apr 13 '17 at 12:23









        Community

        1




        1










        answered Jun 5 '16 at 5:01









        naroomnaroom

        1012




        1012



























            draft saved

            draft discarded
















































            Thanks for contributing an answer to Ask Ubuntu!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid


            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.

            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f313554%2fhow-to-control-gnome-terminal-from-python-scrypt%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Virtualbox - Configuration error: Querying “UUID” failed (VERR_CFGM_VALUE_NOT_FOUND)“VERR_SUPLIB_WORLD_WRITABLE” error when trying to installing OS in virtualboxVirtual Box Kernel errorFailed to open a seesion for the virtual machineFailed to open a session for the virtual machineUbuntu 14.04 LTS Virtualbox errorcan't use VM VirtualBoxusing virtualboxI can't run Linux-64 Bit on VirtualBoxUnable to insert the virtual optical disk (VBoxguestaddition) in virtual machine for ubuntu server in win 10VirtuaBox in Ubuntu 18.04 Issues with Win10.ISO Installation

            Are there any comparative studies done between Ashtavakra Gita and Buddhim?How is it wrong to believe that a self exists, or that it doesn't?Can you criticise or improve Ven. Bodhi's description of MahayanaWas the doctrine of 'Anatta', accepted as doctrine by modern Buddhism, actually taught by the Buddha?Relationship between Buddhism, Hinduism and Yoga?Comparison of Nirvana, Tao and Brahman/AtmaIs there a distinction between “ego identity” and “craving/hating”?Are there many differences between Taoism and Buddhism?Loss of “faith” in buddhismSimilarity between creation in Abrahamic religions and beginning of life in Earth mentioned Agganna Sutta?Are there studies about the difference between meditating in the morning versus in the evening?Can one follow Hinduism and Buddhism at the same time?Are there any prohibitions on participating in other religion's practices?Psychology of 'flow'

            Where is the suspend/hibernate button in GNOME Shell? Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 23, 2019 at 23:30 UTC (7:30pm US/Eastern)No suspend option in UI on Bionic BeaverHow can I set sleep mode in ubuntu18.04 LTS and what is the short cut key to do so?17.10 suspend not availableUbuntu 18.04 LTS missing sleep optionUbuntu 18.04 LTS - missing suspend option when power button is pressedHow to put Thinkpad X1 Extreme to sleep in Ubuntu 18.10?Suspend Button in interactive power button menu18.04 - Keep programs running after logging outway to disable Hibernate from within gconf-editor so button disappears?How can I hibernate from GNOME Shell?How can I hibernate/suspend from the command line and do so at a specific timeNo permission to suspend/hibernate after upgrading to 12.10MATE - Missing Suspend and Hibernate buttons, pressing power button shutdowns system immediatelyUbuntu 14.04: Suspend, Hibernate and Suspend-hybrid in the menu?Change “power-button-action” comand for “hibernate” option in GNOME 3.18Shutdown / Power off button does always go to suspend on 17.10Hibernate after suspend stopped working in 17.10Why doesn't the keyboard screenshot button work on Ubuntu with GNOME shell?