Results 1 to 4 of 4

Thread: open shell script on button click

  1. #1
    Join Date
    Feb 2005
    Location
    EU
    Beans
    549
    Distro
    Ubuntu 12.04 Precise Pangolin

    open shell script on button click

    Hi! I started to learn some very basic programming and need some help please. i am working with anjuta to create a gui with some buttons.

    When a button is clicked i want to run a shell script, that preforms some tasks.

    I created the gui with glade, and added the "Clicked" Signal to the button, then i need to attach the actual funcion to the button and that's where i dunno what to do.

    in the file "src/callbacks.c"

    is the line
    Code:
    on_button1_clicked            (GtkButton       *button,
                                            gpointer         user_data)
    {
    
    }
    so can someone tell me what to add that it opens a local script in a new terminal?

    Thanks!

  2. #2
    Join Date
    Jun 2005
    Location
    Flagstaff, AZ
    Beans
    13

    Re: open shell script on button click

    1. Install the manpages-dev package.

    2. Pull up the man page for "fork", that will show you how to start anther process. Also look at the "exec" man pages ("execv" is one).

    Here is roughly what you'd write if you wanted to run "/home/user/bin/burnit" with the argument "pics":

    Code:
    #include <unistd.h>
    #include <sys/types.h>
    #include <sys/wait.h>
    
    on_button1_clicked            (GtkButton       *button,
                                            gpointer         user_data)
    {
        int status;
        if (fork() == 0) {
            execl("/home/user/bin/burnit", "pics");
        }
        wait(&status);
    }
    The control will return to the GUI after the script has been run.

  3. #3
    Join Date
    Jun 2005
    Location
    Flagstaff, AZ
    Beans
    13

    Re: open shell script on button click

    Actually, there's a much simpler way. This essentially does the same thing as what I wrote above. You can see more on "system" by typing "man system".

    Code:
    #include <stdlib.h>
    
    on_button1_clicked            (GtkButton       *button,
                                            gpointer         user_data)
    {
        system("/home/user/bin/burnit pics");
    }

  4. #4
    Join Date
    Feb 2005
    Location
    EU
    Beans
    549
    Distro
    Ubuntu 12.04 Precise Pangolin

    Re: open shell script on button click

    Perfect. Thanks a lot!

    one more question:

    i want to attach a terminal in the gui (like in emelfm) to see the error when a script fails.

    But i could not figure out which selector to use. Is it enough to use a scrolled window in the gui, and then attach a function to it that will display a terminal?

    cheers

Bookmarks

Posting Permissions

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