Cannot get pipes to work with glibmm
- From: Bastien Dalla Piazza <bastien dallapiazza gmail com>
- To: "gtk-app-devel-list gnome org" <gtk-app-devel-list gnome org>
- Subject: Cannot get pipes to work with glibmm
- Date: Sat, 17 Oct 2009 17:37:56 +0200
Hi,
I don't know if this is the correct mailing list so redirect me if not.
In a Gtkmm project, I'm using Glib::spawn_async_with_pipes to execute
and control a child process (gnugo in the example). But I cannot get it
to work!
For example:
In the following code, I just redirect the gnugo stdin and stdout to my
program:
#include <glibmm.h>
#include <vector>
#include <string>
#include <iostream>
int main(int argc, char** argv)
{
Glib::init();
int fd_stdin, fd_stdout; //file descriptors
Glib::Pid pid;
Glib::RefPtr<Glib::IOChannel> ch_stdin, ch_stdout;
std::vector<std::string> arguments;
arguments.push_back("gnugo");
arguments.push_back("--mode");
arguments.push_back("gtp");
/spawn gnugo
Glib::spawn_async_with_pipes(Glib::get_current_dir(),
arguments,Glib::SPAWN_SEARCH_PATH,
sigc::slot<void>(),
&pid,&fd_stdin,&fd_stdout);
//create the IOChannel from the file descriptors
ch_stdin=Glib::IOChannel::create_from_fd(fd_stdin);
ch_stdout=Glib::IOChannel::create_from_fd(fd_stdout);
Glib::ustring input,output;
//a stupid loop to test whether the pipes work
while(true){
std::cin>>input;
ch_stdin->write(input.append("\n"));
ch_stdout->read_to_end(output);
std::cout<<output<<std::endl;
}
}
Any idea what I am doing wrong?
Thanks!
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]