LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 10-20-2010, 04:31 PM   #1
widapol
LQ Newbie
 
Registered: Sep 2010
Posts: 16

Rep: Reputation: 0
textbox in C


Hi all,
I am using gtk to program GUI. How can I show the output of shell command into a textbox, ex ps -efc command ?
 
Old 10-20-2010, 07:20 PM   #2
MTK358
LQ 5k Club
 
Registered: Sep 2009
Posts: 6,443
Blog Entries: 3

Rep: Reputation: 723Reputation: 723Reputation: 723Reputation: 723Reputation: 723Reputation: 723Reputation: 723
This question is more about capturing the output of a process, not displaying it in a text box.
 
Old 10-20-2010, 07:22 PM   #3
paulsm4
LQ Guru
 
Registered: Mar 2004
Distribution: SusE 8.2
Posts: 5,863
Blog Entries: 1

Rep: Reputation: Disabled
The easiest way I can think of is:
1. Use popen() to read the text:
Code:
  #define MAXLEN 80
  char input_buf[MAXLEN+1] = "";
  FILE *fp = popen ("ps -efc", "r");
  if (fp)
  {
    fgets (input_buf, MAXLEN, fp);
    input_buf[strlen(input_buf)-1] = '\0';
  }
2. Use a GTK Text View widget to display it:
Code:
  GtkWidget *view = NULL;
  GtkTextBuffer *buffer = NULL;

  view = gtk_text_view_new ();
  buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (view));
  gtk_text_buffer_set_text (buffer, input_buf, strlen (input_buf));
  ...
 
Old 10-21-2010, 11:45 AM   #4
widapol
LQ Newbie
 
Registered: Sep 2010
Posts: 16

Original Poster
Rep: Reputation: 0
It works. Thanks !
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
color in dialog --textbox insamniac Programming 1 09-22-2009 09:31 AM
tab button in textbox Four LQ Suggestions & Feedback 0 02-14-2008 11:07 PM
Change TextBox Color rn5a Linux - Newbie 3 09-23-2007 06:14 PM
insert textbox in openoffice Four Linux - Newbie 4 03-23-2006 10:07 PM
Reading integers in a GTK textbox... Claus Programming 2 11-04-2003 08:44 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 07:16 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration