Glib::MainContext::signal_child_watch is not working



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;
}



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]