Search code examples
cgedit

Opening a file externally using C program


I'd like to create a program that causes a running gedit process to open a .txt file in a new tab using C. The file would be the argument I supply to the program. However, I'd like to avoid using system() altogether.

I'm on Linux. Is this possible? If so, by what means?


Solution

  • You don't need system(). You can use fork/execlp

    if(!fork())
        execlp("gedit", "gedit", filename, NULL);
    

    The version of gedit that's on my laptop uses a new tab by default if there's a running instance already, but I'm not sure about other versions.