sudo vim /etc/resolv.conf
nameserver 192.168.12.1
Tôi tạo blog này để lưu lại những kiến thức mình tìm hiểu và nghiên cứu được
Thứ Hai, 11 tháng 3, 2013
How to get results from a system command in linux
Ví dụ để lấy kết quả từ system command trong linux
#include <stdio.h>
#include <stdlib.h>
int main( int argc, char *argv[] )
{
FILE *fp;
int status;
char path[1035];
/* Open the command for reading. */
fp = popen("/bin/ls /etc/", "r");
if (fp == NULL) {
printf("Failed to run command\n" );
exit;
}
/* Read the output a line at a time - output it. */
while (fgets(path, sizeof(path)-1, fp) != NULL) {
printf("%s", path);
}
/* close */
pclose(fp);
return 0;
}
Đăng ký:
Nhận xét (Atom)