LinuxQuestions.org
Share your knowledge at the LQ Wiki.
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 08-19-2003, 03:34 PM   #1
dfuse
Member
 
Registered: May 2003
Location: Leuven, Belgium
Distribution: Gentoo Linux
Posts: 42

Rep: Reputation: 15
getting output from a program executed from c++


Hey, when I try to determine the total size of a directory (in Qt, C++) with a recursive function, it takes a while for large directories. So I was wondering how I could use the 'du' command on the directory and parse the output of that command to a QString (without the user noticing it,i.e. not opening an extra xterm) I know this should be possible, I just don't know how. If anybody could set me in the right direction, I'd be very happy!
 
Old 08-19-2003, 04:01 PM   #2
kev82
Senior Member
 
Registered: Apr 2003
Location: Lancaster, England
Distribution: Debian Etch, OS X 10.4
Posts: 1,263

Rep: Reputation: 51
you need to look up these functions, the first choice is superior

1) pipe(), fork(), dup2(), exec*()
OR
2) popen(), pclose()

i think youd be better with your recursive function though, for something simple like this its easier to write your own code.

btw - du will take just as long as your own function, it does the same thing.
 
Old 08-20-2003, 05:39 AM   #3
dfuse
Member
 
Registered: May 2003
Location: Leuven, Belgium
Distribution: Gentoo Linux
Posts: 42

Original Poster
Rep: Reputation: 15
OK thanks for the help! I'll try it out. Are you sure du is as fast (slow) as a simple recursive function? It can take up to 2sec to determine the size of my mp3 dir, with du it is instantaneously. Maybe because in my function I have to make a new QFileInfo everytime to determine the filesize.
 
Old 08-20-2003, 05:48 AM   #4
kev82
Senior Member
 
Registered: Apr 2003
Location: Lancaster, England
Distribution: Debian Etch, OS X 10.4
Posts: 1,263

Rep: Reputation: 51
oh, i thought you were using opendir and stat in your recursive function, i dont know how fast/slow the qt method is.

for grabbing the output of du check out www.advancedlinuxprogramming.com chapters 3 and 5.4, it explains the above mentioned functions.
 
Old 08-21-2003, 05:23 AM   #5
UltimaGuy
Member
 
Registered: Aug 2003
Location: Chennai, India
Distribution: PCLinuxOS .92, FC4
Posts: 840

Rep: Reputation: 32
Hei, kev82, that was a good link. Do you have any such links. If so, please post it.
 
Old 08-21-2003, 08:18 AM   #6
kev82
Senior Member
 
Registered: Apr 2003
Location: Lancaster, England
Distribution: Debian Etch, OS X 10.4
Posts: 1,263

Rep: Reputation: 51
umm, what sort of links do you want, i have a bad habbit of not writing down or bookmarking links, i just remember where i found them.
 
Old 08-22-2003, 02:24 AM   #7
UltimaGuy
Member
 
Registered: Aug 2003
Location: Chennai, India
Distribution: PCLinuxOS .92, FC4
Posts: 840

Rep: Reputation: 32
Well, the sort of links that help in understanding and boosts us towards system programming in Linux. I prefer C++ over C, and if you have any links, I will thank you if you share it.
 
  


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
Tk: Storing Output of Program Kenji Miyamoto Programming 4 06-25-2005 01:57 AM
program console output using C xrado Programming 5 04-04-2005 02:48 PM
why output is wrong ( C Program ) minil Programming 7 02-23-2005 06:05 AM
Kylix Program can not be executed outside Kylix vinsky2002 Linux - Software 1 01-10-2005 08:35 AM
C function to execute a program and return the output of the program ryan.n Programming 4 08-14-2004 10:11 PM

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

All times are GMT -5. The time now is 07:19 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