> #include <glibmm.h>
> #include <iostream>
>
> #include <unistd.h>
>
> void finished_process(int pid, int ret)
> {
> std::cout << "Process finished: " << pid << "|" << ret <<
> std::endl;
> }
>
> int main()
> {
> int stdout_fd, pid;
> Glib::ustring line;
> std::vector<std::string> command;
>
> 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::signal_child_watch().connect(sigc::ptr_fun(finished_process),
> pid);
>
> Glib::RefPtr<Glib::IOChannel> io =
> Glib::IOChannel::create_from_fd(stdout_fd);
>
> sleep(5);
>
> while (io->read_line(line) != Glib::IO_STATUS_EOF)
> std::cout << line;
>
> io->close();
> close(stdout_fd);
> std::cout << "Exit" << std::endl;
> }