FedoraForum.org - Fedora Support Forums and Community
Page 1 of 2 1 2 LastLast
Results 1 to 15 of 17
  1. #1
    Join Date
    Dec 2007
    Posts
    33

    Launcher for terminal command

    Is there a way to create a launcher in Gnome to open a terminal and run a command? I've tried to use /bin/bash followed by the command but when I run it the terminal opens and then closes immediately. I thought I had read somewhere that there was a way to make the terminal remain open. Any help would be appreciated.

  2. #2
    scottro's Avatar
    scottro is offline Retired Community Manager -- Banned from Texas by popular demand.
    Join Date
    Sep 2007
    Location
    NYC
    Posts
    8,127
    Yes, the command would be <terminal-name> -e command.

    So, for example, if you wanted to launch mutt in a gnome-terminal (the standard terminal in gnome, oddly enough)

    gnome-terminal -e mutt

    The -e is for exec.

    If I understand your question, I've answered it. (However, not using gnome, I'm not sure what you mean by launcher, so I might have only answered half of it.)

  3. #3
    Join Date
    Dec 2007
    Posts
    33
    Your suggestion gives me the same results. Maybe I should try to clarify the issue. I have a program called pwgen that is run from the command line to create random (easy to remember) passwords. I am trying to create a launcher (icon, or shortcut, on the desktop) that I can use to open a terminal and run the command.

    I would like to do the same thing for other command line programs and put them in a shortcut directory for visibility. I lose sight of some of the command line programs that I don't use on a regular basis and this would help me to keep tabs on them visually. Or to put it another way. I add software to my system, use it once, and 6 months from now when I want to use it again I can't remember the command. One of the joys of growing old. Anyway, I hope this helps clarify my objective. Thanks for your help.

  4. #4
    scottro's Avatar
    scottro is offline Retired Community Manager -- Banned from Texas by popular demand.
    Join Date
    Sep 2007
    Location
    NYC
    Posts
    8,127
    Hrrm, you're right, I just tried it on FreeBSD with the same result. Hold on a second here.

    Ok, it's after midnight and google isn't giving me a quick answer. Obviously it's something about pwgen. (If for example, I do -e mutt, that works.)

    Please keep me posted on your results, and in the interim, I'll be looking into it myself.

  5. #5
    scottro's Avatar
    scottro is offline Retired Community Manager -- Banned from Texas by popular demand.
    Join Date
    Sep 2007
    Location
    NYC
    Posts
    8,127
    Well, I figured out *why* it's happening, but I'm too tired to figure out how to fix it.
    It runs the command and then exits. Once it exits, the terminal closes as well.
    Whereas something like mutt doesn't exit until you type q for quit.

    So, the trick is to keep it from exiting. In other words, you type pwgen [options] and it prints the password or passwords and then exits, bringing you back to the command prompt. Any command that will take you back to the command prompt, such as ls or whatever, will do the same thing.

  6. #6
    scottro's Avatar
    scottro is offline Retired Community Manager -- Banned from Texas by popular demand.
    Join Date
    Sep 2007
    Location
    NYC
    Posts
    8,127
    This will put the result in a text file, though it still doesn't keep the terminal open.

    gnome-terminal -e sh -c $(pwgen 8 1 > pw.txt)

    You can then read pw.txt at your leisure.
    I have no idea if that's of any use to you. I really have to get to sleep. If it helps your googling, the problem is keeping the child process open rather than immediately returning to the parent. Trying gnome-terminal -e . pwgen didn't work either. (The space and period keep it in the parent shell, but one just gets a permission denied on execvp, even if one runs it as root).

  7. #7
    scottro's Avatar
    scottro is offline Retired Community Manager -- Banned from Texas by popular demand.
    Join Date
    Sep 2007
    Location
    NYC
    Posts
    8,127
    Here's an extremely kludgy script that would do what I think you want, that is, to have something opened where you can see the results of pwgen

    #!/bin/sh
    pwgen 8 1 > pwgen.txt
    gnome-terminal -e pwgen.txt

    Afterwards, you'll have to close it. (By the way, I'm just using 8 1 as the arguments as an example--on FreeBSD, it won't run unless I give it some arguments--hrrm, sounds like some people I know, but anyway).

    This will, after opening the terminal, open vi, which won't just run and close. Then, you can close vi after you've gotten your information. (Or gedit or any text editor--the point is to not just run a command which finishes right away.)

  8. #8
    scottro's Avatar
    scottro is offline Retired Community Manager -- Banned from Texas by popular demand.
    Join Date
    Sep 2007
    Location
    NYC
    Posts
    8,127
    This will work, but not with Gnome-terminal, at least on CentOS. It will work with xterm.

    The command

    xterm -hold -e "pwgen"

    It works with xterm and uxterm as well as urxvt. I don't know about terminals, you'd have to view their man page and see if there's a "hold" option.

  9. #9
    Join Date
    Dec 2007
    Posts
    33
    Sorry it's taken a while to get back with you (had to take time out for sleep and then work). I agree that your first respone (gnome-terminal -e pwgen) should work. I tried it with the top command and it works exactly as if I opened a terminal and ran it. I'll definitely use this method initially and it will probably work for me in many cases. I may look into the xterm that you mentioned. Thanks for your help. I really appreciate it.

  10. #10
    Join Date
    Dec 2008
    Posts
    59
    Right click on your desktop and create a new launcher and type the command in the command box.

    I just tested it and it works.

  11. #11
    scottro's Avatar
    scottro is offline Retired Community Manager -- Banned from Texas by popular demand.
    Join Date
    Sep 2007
    Location
    NYC
    Posts
    8,127
    Don't worry about taking time to get back. As long as you report final results.

    Actually, I might have gotten unclear as it got later. Actually, doing gnome-terminal -e pwgen should close immediately. The command itself is the parent process, the child process, that of opening the terminal and running pwgen is expected to close when finished. That's why the
    -hold option of xterm is handy.

    The other way would be that kludgy way I mentioned, that of making the file, then opening it in vi or other text editor. The reason is that although the text editor is also a child process, it will stay open waiting for input (in other words, for you to edit it.)

    As for ~su's solution, I don't use Gnome myself (see my first post) but if that works and leaves it open, that would obviously be the best and quickest way to get what you want. I don't know how Gnome creates launchers and how they work, but in that case, I would guess it's the same as just opening a terminal and typing the command. So, it's a parent, rather than child, so it would stay open, or at least that's my guess.

    At any rate, it was fun to try various things and find a solution.

  12. #12
    Join Date
    Dec 2008
    Posts
    59
    That's interesting.

    Do you use KDE?

  13. #13
    PabloTwo's Avatar
    PabloTwo is offline "Registered User" T-Shirt Winner
    Join Date
    Mar 2007
    Location
    Seville, FL
    Posts
    7,572
    I wrestled with this same problem some time back. My goal: create a desktop launcher that would open a terminal, tail the last 25 lines of /var/log/messages and grep for "CONNECT", in order to ascertain what speed my modem had just connected at after dialing up.

    Yeah, that worked, except the terminal would pop open, display the line, and then close in such speedie fashion one didn't have time to read it.

    My solution: Instead of putting the whole command line string in the launcher, I now use the launcher to run a bash script. The script takes the output of grep, uses cut to trim it down to what I want to see and sets the result as a variable, then displays the variable (text string) in a zenity window, which will stay open until you close it.

    With this method, if all you want to do is display some text, and your terminal of choice doesn't offer a "-hold", or equivalent option, no problem, because you never call up a terminal in the first place.
    Code:
    ~/> cat /usr/bin/speed
    #!/bin/bash
    # Report modem connection speed
    
    tail -30 /var/log/messages | grep CONNECT > /var/tmp/speed
    SPEED=$( cut -c38- /var/tmp/speed )
    zenity --title "Dialup Connection Speed" --info --text "$SPEED"
    Of course, you would create your script to accomplish whatever it is you want to display.

    Edit: Just to test imageshack...
    Last edited by PabloTwo; 25th December 2008 at 03:50 AM.

  14. #14
    Join Date
    Dec 2007
    Posts
    33
    scottro, thanks for all your help. I added xterm to my computer and using xterm -hold -e "pwgen" is giving me exactly what I wanted.

    PabloTwo, thanks for the zenity idea. I couldn't get it to work for this particular situation but I've already found other applications where I can use it.

  15. #15
    PabloTwo's Avatar
    PabloTwo is offline "Registered User" T-Shirt Winner
    Join Date
    Mar 2007
    Location
    Seville, FL
    Posts
    7,572
    Here is a working version bash script to use zenity with the pwgen program:
    Code:
    #!/bin/bash
    # Generate a new random password
    # /usr/bin/newpass
    
    /usr/bin/pwgen -nc > ~/.foo
    NEWPASS=$( cat ~/.foo )
    rm ~/.foo
    zenity --title "Your Password Is:" --info --text "$NEWPASS"
    Just paste the above into a file, name it "newpass" (or any name you want that doesn't conflict with existing names), put it in /usr/bin/ and make it executable. Then in your launcher: use the command newpass. There is no obligation to use this as you already have a working solution that you are happy with. Just providing an alternative option, and, if nothing else, giving you some pointers/ideas on how to use zenity for other things.
    Last edited by PabloTwo; 26th December 2008 at 05:56 PM.

Page 1 of 2 1 2 LastLast

Similar Threads

  1. launcher with sudo, without a terminal
    By colifa in forum Using Fedora
    Replies: 3
    Last Post: 6th December 2012, 02:39 PM
  2. Desktop Launcher command line from terminal?
    By bg3075 in forum Using Fedora
    Replies: 1
    Last Post: 28th June 2009, 03:35 PM
  3. Replies: 5
    Last Post: 28th August 2006, 01:56 PM
  4. create a shortcut (launcher) for root terminal on my desktop
    By oliver-fedora in forum Using Fedora
    Replies: 12
    Last Post: 31st May 2006, 02:51 AM
  5. Terminal Server Client launcher not launching.
    By JoHandsum in forum Using Fedora
    Replies: 1
    Last Post: 7th February 2005, 10:12 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •