system系統呼叫的使用

2021-07-15 20:30:00 字數 622 閱讀 1441

system() 系統呼叫在應用中很廣泛;可以直接在c**中呼叫命令,執行一些特殊操作,用法如下.

1.  直接執行命令:

可以在c檔案中直接執行命令,這是基本用法,例如:

system("mkdir test");

system("chmod 777 test.bin");

等等 2.  如果需要執行的命令是變動的,則可以使用字串變數來執行:

char  cmd_buf[20] = ;

cmd_buf = "mkdir test";

system(cmd_buf);

cmd_buf = "chmod 777 test.bin";

system(cmd_buf);

等等 3.  如果執行的命令中有引數需要傳遞,則也可以使用字串變數來執行:

char cmd_buf[20] = ;

int gain_para = 7;

sprintf(cmd_buf, "/data/set_gain.sh %d", gain_para);

system(cmd_buf);

獲取system系統呼叫的輸出

include include include include include static int getresultfromsystemcall const char pcmd,char presult,int size hide stdout int bak fd dup stdout fil...

system函式呼叫

相關函式 fork,execve,waitpid,popen 表頭檔案 include 定義函式 int system const char string 函式說明 system 會呼叫fork 產生子程序,由子程序來呼叫 bin sh c string來執行引數string字串所代表的命令,此命 ...

使用system()函式呼叫Linux指令碼

system 函式在函式庫中,通過他可以呼叫linux中的指令碼。具體使用可以用 man system來看。這個函式就乙個引數,就是你要執行的命令的字串。比如,呼叫的指令碼位於 home usr joker test.sh,那麼就可以這樣在c c 中呼叫system home usr joker t...