LinuxQuestions.org
Help answer threads with 0 replies.
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 04-30-2012, 05:23 PM   #1
szzed
LQ Newbie
 
Registered: Apr 2012
Posts: 8

Rep: Reputation: Disabled
Parse c external command output in real time


Hi All!
I would like to write in C a gtk2.0 application, that reads the output of clamscan program. I've tried popen, glib spawn, but everything seems to be not real time. The clamscan starts, writes a lot of things to the stdout, but I could read it from the calling process, when clamscan stops. I need to write out the lines on the gtk window (into a textview widget) as it would be the stdout.
Is there any way to solve this? Of course I want to do this in C.
Thanks for replies!
 
Old 04-30-2012, 09:11 PM   #2
ta0kira
Senior Member
 
Registered: Sep 2004
Distribution: FreeBSD 9.1, Kubuntu 12.10
Posts: 3,078

Rep: Reputation: Disabled
Try non-blocking reads, or read one character at a time. Also, are you sure clamscan sends output in real time (an not just when the buffer is full)?
Kevin Barry
 
Old 05-01-2012, 02:38 AM   #3
szzed
LQ Newbie
 
Registered: Apr 2012
Posts: 8

Original Poster
Rep: Reputation: Disabled
It seems that clamscan sends output when the buffer is full, but just when I run it as external program. If I run it from console, the output comes real time.
But not just clamscan behaves like this. I wrote a little program, that writes output to the stdout and to stderr. What is written to stderr, appears real time, but what is written to stdout, appears at the end of the program. If I redirect all the output to the stderr, the program fails. But I don't think this should be the way these programs work. But then how?
 
Old 05-01-2012, 08:27 AM   #4
zsd
Member
 
Registered: Dec 2005
Location: Nova Scotia
Distribution: Slackware
Posts: 94

Rep: Reputation: 54
If you have expect and unbuffer on your system, you may be able to use unbuffer as part of your popen() command to help you out.

It is considered to be a "feature" that stderr output is unbuffered, whereas stdout is buffered. (Of course, someone writing a C program can use fflush(stdout) to flush the stdout buffer if they want. I don't know clamscan, but it may be that clamscan does fflush(stdout) if isatty(fileno(stdout)), and otherwise it just buffers it, which may explain what you are seeing).

Anyway, unbuffer is written for exactly this situation, so you may find it useful.

Cheers.

Jim
 
Old 05-04-2012, 01:48 PM   #5
szzed
LQ Newbie
 
Registered: Apr 2012
Posts: 8

Original Poster
Rep: Reputation: Disabled
Thank you all helping me out this question.
zsd's suggestion solved my problem, now I have a fully functional program. But this took me into a new problem, but it's gonna be subject of a new thread.
Again thank you all!
 
  


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
awk not parse the output of nc command! mythcat Linux - General 6 09-30-2011 03:00 AM
print AND real-time output of PING command anrivel Linux - Networking 1 05-04-2011 12:13 AM
how can I format/parse the output of time? luusac Linux - Newbie 4 04-09-2009 05:18 AM
How do I parse the output of a command that output to standard out? gauol Programming 9 01-17-2008 01:54 PM
how to pipe and parse output of a command learnfast Linux - Newbie 2 06-15-2005 04:55 AM

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

All times are GMT -5. The time now is 04:50 PM.

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