[fxruby-users] capturing stdout, stdin and stderr

angico angico at angico.org
Thu Nov 6 13:38:46 EST 2008


Em Qui, 2008-11-06 às 08:13 -0500, Jeroen van der Zijp escreveu:

> You can open two pipes and pass these along as stdin and stdout of the
> program you're starting:
> 
> 	pipe(in);
> 	pipe(out);
> 
> 	pid=fork();
> 
> 	if(pid==0){
> 	  ::close(out[0]);
> 	  ::dup2(out[1],STDOUT_FILENO);
> 	  ::close(in[1]);
> 	  ::dup2(in[0],STDIN_FILENO);
> 	  ::execl(path,...,NULL);
> 	  ::exit(1);
> 	  }
>         else if(pid>0){
>           ::close(out[1]);
>           ::close(in[0]);
>           getApp()->addInput(obj,ID_INPUTREAD,out[0],INPUT_READ,(void*)(FXival)out[0]);
> 	  }
> 
> In a nutshell.  There are details omitted for brevity's sake.
> 
> The handler for ID_INPUT_READ will get invoked when the program "path" writes to
> stdout.  It will then have to present this text to the user and write to in[1]
> to talk back to the program (using write()).
> 
> Hope this helps,
> 
> 		- Jeroen
> 

Yeah! That's exactly what I was looking for. Thank you very much!

-- 

angico
------
home page: www.angico.org
Gnu/Linux, FLOSS, Espiritismo, e eu por mim mesmo 8^I
------
contatos:
email: angico at angico.org
skype: an.gi.co
------



More information about the fxruby-users mailing list