How to open a file using my own program and call it another program?

Task:
I would like to create my own file extension, so when I click on a specific “point” file, my program will open it. However, this program that I wrote is just the average person in that it will do some processing, but ultimately transfer this file to another program for processing.

Example:
So, for example, all text files with the extension .foowill be displayed as if they were opened with gedit. But in fact, what happens is that they are opened by one of my programs, and, in turn, my program transfers this file to gedit.

my C ++ program for this is as follows:

#include <string>
#include <cstdlib>

int main(int argc,  char** argv) {

    //open file with gedit
    system(("(gedit " + std::string(argv[1]) + " > /dev/null &)").c_str());

    //do other processing
    //...
}

I believe that when you click on a file and the operating system reports that it is opened using a specific program, this file name is passed to the C ++ program as the second argument of this program (as index 1, since the index index is the name programs). &runs in such a way that it geditstarts as a background process, and an additional one ()around the operator ensures that geditit will not be closed when the parent shell is closed.

:
, , , , $PATH, , , . , .

, :
script, ,
, Right Click->Properties->Open With enter image description here
, . , , . ? - ? script , ? ? -?

Ubuntu.

+4
1

:

int main(int argc,  char** argv) {
    std::system("gnome-terminal");
}
0

Source: https://habr.com/ru/post/1524698/


All Articles