Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8163989
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T19:12:07+00:00 2026-06-06T19:12:07+00:00

I am trying to make a PyGtk Gui, that has a button. When the

  • 0

I am trying to make a PyGtk Gui, that has a button. When the user presses this button, gnome-terminal prompts the user to write their password.

Then it will clone this Git repository for gedit JQuery snippets.

And then, it copies the js.xml file to /usr/share/gedit/plugins/snippets/js.xml

In the end, it forcefully removes the Git repository.

The command:

gnome-terminal -x sudo git clone git://github.com/pererinha/gedit-snippet-jquery.git && sudo cp -f gedit-snippet-jquery/js.xml /usr/share/gedit/plugins/snippets/js.xml && sudo rm -rf gedit-snippet-jquery

It works fine in my terminal.

But, via the GUI it just opens, I add my password, press enter, and then it closes again.

I’d like to only run the command to the first &&

This is my Python function (with command):

def on_install_jquery_code_snippet_for_gedit_activate(self, widget):
    """ Install Jquery code snippet for Gedit. """
    cmd="gnome-terminal -x sudo git clone git://github.com/pererinha/gedit-snippet-jquery.git && sudo cp -f gedit-snippet-jquery/js.xml /usr/share/gedit/plugins/snippets/js.xml && sudo rm -rf gedit-snippet-jquery"
    p = Popen(cmd, shell=True, stdin=PIPE, stdout=PIPE, stderr=STDOUT,
             close_fds=False)
    self.status.set_text(p.stdout.read()) #show response in 'status
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T19:12:09+00:00Added an answer on June 6, 2026 at 7:12 pm

    To directly answer your question, read below. But there’s a lot of problems with your program, some of which I cover in “Better practice.”


    By default, subprocess.Popen commands are supplied as a list of strings.

    However, you can also you can use the shell argument to execute a command “formatted exactly as it would be when typed at the shell prompt.”

    No:

    >>> p = Popen("cat -n file1 file2")
    

    Yes:

    >>> p = Popen("cat -n file1 file2", shell=True)
    >>> p = Popen(["cat", "-n", "file1", "file2"])
    

    There are a number of differences between these two options, and valid use cases for each. I won’t attempt to summarize the differences- the Popen docs already do an excellent job of that.


    So, in the case of your commands, you’d do something like this:

    cmd = "gnome-terminal -x sudo git clone git://github.com/pererinha/gedit-snippet-jquery.git && sudo cp -f gedit-snippet-jquery/js.xml /usr/share/gedit/plugins/snippets/js.xml && sudo rm -rf gedit-snippet-jquery"
    p = Popen(cmd, shell=True, stdin=PIPE, stdout=PIPE, stderr=STDOUT,
              close_fds=False)
    

    Better practice

    However, using Python as a wrapper for many system commands is not really a good idea. At the very least, you should be breaking up your commands into separate Popens, so that non-zero exits can be handled adequately. In reality, this script seems like it’d be much better suited as a shell script. But if you insist on Python, there are better practices.

    The os module should take the place of calls to rm and cp. And while I have no experience with it, you might want to look at tools like GitPython to interact with Git repositories.

    Compatibility concerns

    Lastly, you should be careful about making calls to gnome-terminal and sudo. Not all GNU/Linux users run Ubuntu, and not everyone has sudo, or the GNOME terminal emulator installed. In its current form, your script will crash, rather unhelpfully, if:

    • The sudo command is not installed
    • The user is not in the sudoers group
    • The user doesn’t use GNOME, or its default terminal emulator
    • Git is not installed

    If you’re willing to assume your users are running Ubuntu, calling x-terminal-emulator is a much better option than calling gnome-terminal directly, as it will call whatever terminal emulator they’ve installed (e.g. xfce4-terminal for users of Xubuntu).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying make a login window where a user is prompted to enter their
I'm trying make an entity with doctrine that has three associations with other entities
Trying to make this jQuery filter that uses .find case-insensitive. For example, when the
Trying to make a simple scroll to top button that smoothly scrolls up and
Trying to make a simple number clicker control for BlackBerry 6/7, like this: At
Trying to make an xna game, where the user needs to tap to stop
Is there a way to make a PyGTK widget partly transparent, so that the
im trying make one replace in string from a array but this dont work
Trying to make this simple applet - the first part just creates a simple
Trying to make this function dynamic instead of static. This was the original code

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.