LinuxQuestions.org
Review your favorite Linux distribution.
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 02-24-2005, 01:14 PM   #1
MylesCLin
Member
 
Registered: Sep 2004
Location: Texas, USA
Distribution: Slack 9.1 with slackware-current packages...
Posts: 164

Rep: Reputation: 30
C: Getting program's output


Is there any way, in C, to execute another program AND get it's output?
I need to run wc -c to get the number of chars in a file.
Any ideas?
 
Old 02-24-2005, 01:19 PM   #2
itsme86
Senior Member
 
Registered: Jan 2004
Location: Oregon, USA
Distribution: Slackware
Posts: 1,246

Rep: Reputation: 58
Look at the popen() function.
 
Old 02-24-2005, 01:20 PM   #3
Matir
Moderator
 
Registered: Nov 2004
Location: San Jose, CA
Distribution: Ubuntu
Posts: 8,507

Rep: Reputation: 118Reputation: 118
Look into popen();.

Though a more portable way to do this would be:
Code:
long filelen(char *fname){
long len;
FILE *f=fopen(fname,"r");
fseek(f,0,SEEK_END);
len=ftell(f);
fclose(f);
return len;
}
Or something similar. Been a while since I've done that in C.
 
Old 02-24-2005, 01:35 PM   #4
MylesCLin
Member
 
Registered: Sep 2004
Location: Texas, USA
Distribution: Slack 9.1 with slackware-current packages...
Posts: 164

Original Poster
Rep: Reputation: 30
You have fixed my problem, danke sehrs!
 
Old 02-24-2005, 06:06 PM   #5
Matir
Moderator
 
Registered: Nov 2004
Location: San Jose, CA
Distribution: Ubuntu
Posts: 8,507

Rep: Reputation: 118Reputation: 118
No problem. Just glad to help.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
Looking for a few program's. Budman21901 Linux - Software 8 10-27-2005 04:00 PM
Suse certification program's hansi umayangan Suse/Novell 1 07-01-2005 12:53 PM
How do I run program's with WINE? kaber Linux - Software 3 09-09-2004 04:41 PM
GNU program's design tda Programming 3 03-16-2003 02:15 AM
Problem's installing program's amp2000 Linux - Software 2 02-22-2002 02:42 AM


All times are GMT -5. The time now is 06:23 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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration