Существует пример, чтобы получить среду редактор по умолчанию, из visudo (Он использует редактор по умолчанию, чтобы открыть файл sudoers) Источник
/*
* Check EDITOR and VISUAL environment variables to see which editor
* the user wants to use (we may not end up using it though).
* If the path is not fully-qualified, make it so and check that
* the specified executable actually exists.
*/
if ((UserEditor = getenv("EDITOR")) == NULL || *UserEditor == '\0')
UserEditor = getenv("VISUAL");
if (UserEditor && *UserEditor == '\0')
UserEditor = NULL;
else if (UserEditor) {
if (find_path(UserEditor, &Editor, getenv("PATH")) == FOUND) {
UserEditor = Editor;
} else {
if (def_flag(I_ENV_EDITOR)) {
/* If we are honoring $EDITOR this is a fatal error. */
(void) fprintf(stderr,
"%s: specified editor (%s) doesn't exist!\n",
Argv[0], UserEditor);
Exit(-1);
} else {
/* Otherwise, just ignore $EDITOR. */
UserEditor = NULL;
}
}
}
Вы можете проверить http://www.opensource.apple.com/source/sudo/sudo-9/sudo/visudo.c для полного кода.
Возможный дубликат [Открыть файл в редакторе по умолчанию из bash] (http://stackoverflow.com/questions/13627767/open-file-in-default-editor-from-bash). –
@ FrédéricHamidi Извините, но я не могу схватить. Это не C++, и кто-то может дать мне альтернативу system(). – Vider7CC
Достаточно честный. Я только пытался указать вам на 'xdg-open'. –