Re: log in text widget



On Thu, 5 Oct 2000, Alexandre Fayolle wrote:

On Thu, 5 Oct 2000, Jose Eusebio Roza Pando wrote:

Hi ,
My application execs linux command with system and i would like to show
the shell messages in a text widget.
Has anybody any idea?
       Eusebio

Use popen().
See http://www.erlenstar.demon.co.uk/unix/faq_2.html#SEC12 for more info.

Sorry, I realize this was a bit dry. 

You can use popen() instead of system to execute the
command. popen() takes two parameters. The first one is the command string
(as you pass to system()) and the second one is the direction of the pipe
that popen() will create: if you use "r", you will be able to read the
standard output of the command, and if you use "w", you will be able to
write to the command stdin. Obviously, you want to use "r" to perform what
you describe. popen() returns a file descriptor, and you can use the
standard calls on this fdesc. You can check the man page for more info.

If your command takes a very short amount of time to run, you can do just
this, and it will work fine. However, if you want to print, say, the
output of a huge make process, you should consider adding your fdesc to
those monitored by GTK, and add a callback on events on this file
descriptor, so that your app won't hang completely while the command runs.

-- 
Alexandre Fayolle
http://www.logilab.com - "Mais où est donc Ornicar ?" - 
LOGILAB, Paris (France).





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