RE: Running Gtk application in new terminal



Here you go.  This code implements a simple command processor, one command of which starts up a gtk app.  I tried it with an app of mine called "ngdcs" and it works.  You might want to read up on fork and exec ("man fork", "man execv") but this does work for me:

#include <stdio.h>
#include <stdlib.h>

int main()
{
    int pid;
    char *argv[2];
    char command[80];

    printf("Enter command, either gtk or sayhello: ");
    while (fgets(command, sizeof(command), stdin) != NULL) {
        if (strcmp(command, "gtk\n") == 0) {
            pid = fork();
            if (pid == 0) {
                argv[0] = "/usr/local/bin/ngdcs";
                argv[1] = NULL;
                (void)execv(argv[0], argv);
                printf("execv failed!\n");
                exit(1);
            }
        }
        else if (strcmp(command, "sayhello\n") == 0)
            printf("hello\n");
        else printf("bad command\n");
        printf("Enter command, either gtk or sayhello: ");
    }
}


From: Abhinav singh [abhinavksingh93 gmail com]
Sent: Thursday, June 05, 2014 8:52 AM
To: Mazer, Alan S (389M)
Cc: gtkmm-list gnome org
Subject: Re: Running Gtk application in new terminal




On Thu, Jun 5, 2014 at 8:57 PM, Alan Mazer <alan s mazer jpl nasa gov> wrote:
On 6/5/2014 12:20 AM, Gavin Lambert wrote:
Quoth Abhinav singh:
I am running a gtk application from another program lets call it "main
program". This program is command driven and proceed according to
command given to it. What my problem is when the command which runs my
gtk application is given into "main program" the terminal gets hang up
till the application window is closed then only my "main program" is
able to process further command given to it.

Is there any way to run my gtk application in entire new terminal or
without terminal associated with it so that my "main program" will be
able to process the next command in the list with gtk application
running in parallel?
It sounds like you're asking how to run a GTK app from a shell script
without waiting for it to end.

You do that just like you'd do it for anything else -- you run it as a
background task (usually by adding & at the end of your command line).


Sounds like a place for fork/exec.  Your main app forks then execs the gtk app.  I'm assuming this is running in a *nix environment, although there are similar constructs on Windows.

_______________________________________________
gtkmm-list mailing list
gtkmm-list gnome org
https://mail.gnome.org/mailman/listinfo/gtkmm-list

Yes, this is running in a nix* environment. Can you please provide me link of tutorial related to fork/exec or some code structure which implement something similar to what you are saying.

Thanks,
Abhinav


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]