I am trying to spawn process with gtkmm but am faced with a problem. Here is the specific snippet of my code:
std::vector<std::string> args, envp;
args.push_back("/usr/libexec/mc/ext.d/doc.sh");
args.push_back("open");
args.push_back("pdf");
envp.push_back("MC_EXT_FILENAME="DATADIR"/bsbguide.pdf");
Glib::spawn_async("", args, envp, Glib::SPAWN_SEARCH_PATH);`
Task is to open a pdf file that is installed in DATADIR
(this var is defined with automake). This variable pushed in envp is essential for opening file using Midnight Commander's stuff. The command
MC_EXT_FILENAME="some_file" /usr/libexec/mc/ext.d/doc.sh open pdf
will exactly open some_file
with a PDF viewer.
The program compiles and works, but when I try to invoke programs with these functions I get this:
(zathura:3014): Gtk-WARNING **: cannot open display:
and nothing happens. Same command from console results in opened pdf file with my PDF viewer (Zathura). I found this in Devhelp:
If you are writing a GTK+ application, and the program you are spawning is a graphical application, too, then you may want to use
gdk_spawn_on_screen()
instead to ensure that the spawned program opens its windows on the right screen.
But no such function I found. Maybe there is a more elegant and correct way to open a file with the user's default PDF, viewer without MC parts? If not, how can I make this works? Even better if it will be in C++ style without gdk_spawn_on_screen
.