-1

I have an GUI based executable in the path /usr/bin in the linux machine This executable takes three arguments - two integer values and one char

Can you let me know how to invoke and run this executable from a user space C++ program

Ðаn
  • 10,934
  • 11
  • 59
  • 95
arunkm
  • 19
  • 3

1 Answers1

0

Not leaving this unanswered for no reason

pid_t runprocess(int arg1, int arg2, char arg3)
{
    static const char program[] = "/usr/bin/...";
    char arg1c[12];
    char arg2c[12];
    char arg3c[2];
    sprintf(arg1c, "%d", arg1);
    sprintf(arg2c, "%d", arg2);
    arg3c[0] = arg3;
    arg3c[1] = 0;
    pid_t pid = vfork();
    if (pid == 0) {
        signal(SIGHUP, SIG_IGN); /* since it's a GUI program, detach from console HUP */
        close(0); /* and detach from stdin */
        if (open("/dev/null", O_RDWR)) _exit(137); /* assertion failure */
        execl(program, program, arg1c, arg2c, arg3c, NULL);
        _exit(errno);
    }
    return pid;
}

Build arguments as strings, fork and exec it. Trivial really. Don't forget to wait().

Since the child process is a GUI process, we detach HUP from the terminal we may or may not be running on and replace stdin with /dev/null.

Joshua
  • 40,822
  • 8
  • 72
  • 132