|
|
| The C Puzzle Book (ISBN: 0201604612) |
 |
List Price: $24.99
Our Price: $24.99
Used Price: $8.00
Release Date: 15 October, 1998
Manufacturer: Addison-Wesley Pub Co (Paperback)
Sales Rank: 52,438
Author: Alan R. Feuer, Alan R. Feuer
|
More Info
|
|
|
Popen
|
2002-01-29 14:10:43
|
| |
c
|
|
|
|
|
Category: source:c:files
|
|
Description: Read the output from other programs using popen
|
|
Platform: unix
|
|
Author: detour
|
|
Viewed: 7995
|
|
Rating: 3.9/5 (48 votes)
|
|
|
| If you have any questions about
this piece of code or still need help, try posting your question on the forum. |
/* popen.c by detour@metalshell.com
*
* Example of reading the output of another
* program using popen() and pclose()
*
* http://www.metalshell.com/
*
*/
#include <stdio.h>
int main() {
FILE *in;
extern FILE *popen();
char buff[512];
/* popen creates a pipe so we can read the output
of the program we are invoking */
if (!(in = popen("netstat -n", "r"))) {
exit(1);
}
/* read the output of netstat, one line at a time */
while (fgets(buff, sizeof(buff), in) != NULL ) {
printf("Output: %s", buff);
}
/* close the pipe */
pclose(in);
}
|
|
|