Hi, All. Is there any tutorial out there on capturing the standard streams (in, out, err) so that we can have an external command (say, scp) display output in a window and get input from user with a dialog box? Thanks, -- 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 ------
afaik, something like that could be done via IO.popen ... somebody correct me if i''m wrong.-- henon On Wed, Nov 5, 2008 at 5:40 PM, angico <angico at angico.org> wrote:> Hi, All. > > Is there any tutorial out there on capturing the standard streams (in, > out, err) so that we can have an external command (say, scp) display > output in a window and get input from user with a dialog box? > > Thanks, > > -- > > 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 > ------ > > _______________________________________________ > fxruby-users mailing list > fxruby-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/fxruby-users >-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://rubyforge.org/pipermail/fxruby-users/attachments/20081105/38d33588/attachment.html>
Example from Programming Ruby book: pig = IO.popen("/usr/local/bin/pig", "w+") pig.puts "ice cream after they go to bed" pig.close_write puts pig.gets On Wed, Nov 5, 2008 at 8:40 PM, angico <angico at angico.org> wrote:> Hi, All. > > Is there any tutorial out there on capturing the standard streams (in, > out, err) so that we can have an external command (say, scp) display > output in a window and get input from user with a dialog box? > > Thanks, > > -- > > 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 > ------ > > _______________________________________________ > fxruby-users mailing list > fxruby-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/fxruby-users >-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://rubyforge.org/pipermail/fxruby-users/attachments/20081106/f4da8220/attachment-0001.html>
Em Qui, 2008-11-06 ?s 09:16 +0400, Rovshan Baghirov escreveu:> Example from Programming Ruby book: > > pig = IO.popen("/usr/local/bin/pig", "w+") > pig.puts "ice cream after they go to bed" > pig.close_write > puts pig.getsThank you, guys. I guess it''s a starting point. But what I really need is to have an application''s stdin "connected" to an FXInputDialog, in order to get user input, instead of the console. Let''s say I want to create a front-end to scp. The user will enter the name of the host and the full filename in a dialog. Then I pass in these data to scp through, say, popen. Ok. Then, scp will need to ask the user for their password. Instead of the console asking the user to enter that password, I''d like to catch this (including the message "angico at 192.168.1.3''s password: ") and present them to the user in an FXInputDialog. I''m not sure if I''m being clear. Anyway, does anybody know how can I achieve this? Any idea? Any tutorial? Thanks, again, -- 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 ------
Jeroen van der Zijp
2008-Nov-06 13:13 UTC
[fxruby-users] capturing stdout, stdin and stderr
On Thursday 06 November 2008, angico wrote:> Em Qui, 2008-11-06 ?s 09:16 +0400, Rovshan Baghirov escreveu: > > Example from Programming Ruby book: > > > > pig = IO.popen("/usr/local/bin/pig", "w+") > > pig.puts "ice cream after they go to bed" > > pig.close_write > > puts pig.gets > > Thank you, guys. I guess it''s a starting point. > > But what I really need is to have an application''s stdin "connected" to > an FXInputDialog, in order to get user input, instead of the console. > > Let''s say I want to create a front-end to scp. The user will enter the > name of the host and the full filename in a dialog. Then I pass in these > data to scp through, say, popen. Ok. Then, scp will need to ask the user > for their password. Instead of the console asking the user to enter that > password, I''d like to catch this (including the message > "angico at 192.168.1.3''s password: ") and present them to the user in an > FXInputDialog. I''m not sure if I''m being clear. > > Anyway, does anybody know how can I achieve this? Any idea? Any > tutorial? > > Thanks, again, >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 -- +----------------------------------------------------------------------------+ | Copyright (C) 07:00 11/ 6/2008 Jeroen van der Zijp. All Rights Reserved. | +----------------------------------------------------------------------------+
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 ------