Christian Seberino <[EMAIL PROTECTED]> writes: > > Netscape sounds interesting.... do you > know how to do this?... does this mean "fork" and "exec" > system calls? I don't suppose it is possible to do this with > PThreads is it? >
You can't do it from a thread, as you'd still need to fork and exec. The following snippet of code loads a URL in an already running Netscape, or launches it if it isn't running. void some_callback(GtkWidget *widget, gpointer data) { gchar buf[MAXPATHLEN]; gchar *url = (gchar *)data; g_snprintf(buf, MAXPATHLEN, "%s/.netscape/lock", g_get_home_dir()); if(lstat(buf, &statbuf)) g_snprintf(buf, MAXPATHLEN, "netscape %s", url); else g_snprintf(buf, MAXPATHLEN, "netscape -remote openURL(%s,new_window)", url); if(!start_browser(buf)) /* show an error dialog */; } gboolean start_browser(const gchar *cmd) { char **args, *ptr, *tokptr; int argc, len, i; pid_t pid; if((pid = fork()) == 0) { if((pid = fork()) == 0) { len = strlen(cmd); argc = 1; for(i = 0; i < len; i++) { if(cmd[i] == ' ') argc++; } args = g_malloc(sizeof(char *) * (argc + 1)); args[argc] = NULL; if(argc == 1) { args[0] = g_malloc(sizeof(char) * (len + 1)); strcpy(args[0], cmd); } else { ptr = g_malloc(sizeof(char) * (len + 1)); strcpy(ptr, cmd); tokptr = strtok(ptr, " "); args[0] = tokptr; i = 1; for(i = 1; tokptr; i++) { tokptr = strtok(NULL, " "); args[i] = tokptr; } args[i] = tokptr; } /* for(i = 0; i < argc; i++) { g_print("arg %d : %s\n", i + 1, args[i]); } _exit(0); */ execvp(args[0], args); } _exit(0); } else if(pid < 0) { return FALSE; } return TRUE; } Chris -- [EMAIL PROTECTED] (work) [EMAIL PROTECTED] (home) _______________________________________________ gtk-list mailing list [EMAIL PROTECTED] http://mail.gnome.org/mailman/listinfo/gtk-list