Hi I sent a mail some days ago with the same issue, Armin suggested me a solution but is not working. Can some tell me why is this not working?.
#include <glibmm.h> #include <iostream> #include <unistd.h> void finished_process(int pid, int ret, Glib::RefPtr<Glib::MainLoop>& loop) { loop->quit(); std::cout << "Process finished: " << pid << "|" << ret << std::endl; } int main() { int stdout_fd, pid; Glib::ustring line; std::vector<std::string> command; Glib::init(); command.push_back("ls"); try{ Glib::spawn_async_with_pipes(".", command, Glib::SPAWN_SEARCH_PATH, sigc::slot<void>(), &pid, NULL, &stdout_fd, NULL); } catch(Glib::SpawnError &e){ std::cout << "Error: " << e.what() << std::endl; return 0; } Glib::RefPtr<Glib::MainLoop> loop(Glib::MainLoop::create()); Glib::RefPtr<Glib::MainContext> context = loop->get_context(); context->signal_child_watch().connect(sigc::bind(sigc::ptr_fun(finished_process), loop), pid); Glib::RefPtr<Glib::IOChannel> io = Glib::IOChannel::create_from_fd(stdout_fd); loop->run(); while (io->read_line(line) != Glib::IO_STATUS_EOF) std::cout << line; io->close(); close(stdout_fd); std::cout << "Exit" << std::endl; } _______________________________________________ gtkmm-list mailing list [hidden email] http://mail.gnome.org/mailman/listinfo/gtkmm-list |
On Thu, 2 Oct 2008 21:33:06 +0200
"Fernando Tarín" <[hidden email]> wrote: > Hi I sent a mail some days ago with the same issue, Armin suggested > me a solution but is not working. Can some tell me why is this not > working?. [snip] There is an exmple of using Glib::SignalChildWatch in the examples sub-directory in the glibmm package, which I suggest you use as a starting point. The only obvious difference I can see is that the example calls Glib::signal_child_watch().connect() directly (rather than through the Glib::MainContext object as in your case). Chris _______________________________________________ gtkmm-list mailing list [hidden email] http://mail.gnome.org/mailman/listinfo/gtkmm-list |
Hi, thanks for your answer, the problem with the source code is that I'm not using
the SPAWN_DO_NOT_REAP_CHILD flag so the child is spawned from an intermediate process and therefore can't be traced from the current process all works as expected adding that flag. On Fri, Oct 3, 2008 at 8:29 PM, Chris Vine <[hidden email]> wrote:
_______________________________________________ gtkmm-list mailing list [hidden email] http://mail.gnome.org/mailman/listinfo/gtkmm-list |
Free forum by Nabble | Edit this page |