Re: calling external programs



On Sat, 2003-10-18 at 06:10, Nix wrote:
In your shoes, I would call popen() instead:

I would use g_spawn_async_with_pipes (see the glib documentation).  It's
more portable than popen (you can't use popen in windows in a
non-console application with some work, which glib does for you) and
will always be there were where GTK is.  Then follow the type of logic
Nix mentioned.

I'm always surprised at what wonderful and elegant functions I find in
the glib routines.  Kudos to the GTK developers for providing this
awesome utility library.  I think it should be considered a standard C
library, especially for things like dynamic strings (way useful for
doing i/o).


Michael


FILE *pfile = popen ("ls -l", "r") ;
char buf[256] = "" ;
int ic = 0 ;

while (!feof (pfile))
  {
  ic = fread (buff, 1, 256, pfile) ;
  /* Now buf contains ic characters of output */
  }

pclose (pfile) ;

See, popen () allows you to treat the input XOR the output of a process
as a file.  This way, you can read from XOR write to it, respectively.

As for the widget to display the text, I'd say a GtkTextView would be a
solution.


_______________________________________________
gtk-app-devel-list mailing list
gtk-app-devel-list gnome org
http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
-- 
Michael Torrie <torriem chem byu edu>



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