前言
system()函數的作用是執行一個shell腳本或者shell指令
popen與system()函數類似,不同點是popen()函數可以獲取運行的shell腳本或者命令的輸出結果
system()
函數參數
#include <stdlib.h>
int system(const char *comand)
參考示例代碼:
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>int main (void)
{char ret[1024] ={0};system ("ps");printf ("ret = %s \n",ret);return 0;
}
運行結果顯示:
可以發現使用system()函數無法獲取運行的結果
popen()
函數原型:
#include <stdio.h>
FILE popen (const char command,const char *mode )
參考示例代碼:
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>int main (void)
{char ret[1024