Как приложение получает имя файла в случае запуска «открыть файл с помощью»?

Например, Windows запускает новый процесс выбранного приложения и передает имя открываемого файла процессу с дополнительным аргументом командной строки (для моего приложения: argv [0] - исполняемый файл, argv [1] - открываемый файл). Ubuntu запускает мое приложение, но процесс не получает никаких дополнительных аргументов (только argv [0]). Как мое приложение может узнать имя файла, который открывает пользователь?

0
задан 11 July 2020 в 13:22

1 ответ

The file manager will pass along the URI of the file that you right-clicked in order to select "Open With".

In linux desktops, applications are launched using a launcher file. A launcher file is a plain text file with the .desktop extension. It contains information for the desktop environment on how to start the application, what icon to use, how and where to display it in the menu, etc. The Open With Other Application" list in Files (nautilus) is populated by the .desktop` files present on your system.

It is in the .desktop file on the Exec= line that arguments are defined. For example, for the editor Gedit, this line is

Exec=gedit %U

Only when the Exec= entry of the .desktop file contains an argument, the system will pass the argument it received from Files (nautilus) to the program.

1
ответ дан 30 July 2020 в 22:09

Другие вопросы по тегам:

Похожие вопросы: