- 论坛徽章:
- 0
|
#include <stdlib.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <fcntl.h>
#include <unistd.h>
#include <errno.h>
#include <string.h>
#define MAX_LINE 1024
int main()
{
FILE *fp;
int len;
if ((fp = popen("ls /web | wc -l", "r")) == NULL)
{
perror("popen failed");
return -1;
}
char buf[MAX_LINE];
fgets(buf, 255, fp);
len=strlen(buf);
buf[len-1]='\0';
printf("%s\n", buf);
int i=atoi(buf);
printf("i is %d \n",i);
if (pclose(fp) == -1)
{
perror("pclose failed");
return -2;
}
return 0;
} |
|