#include
#include
#include
int main(void)
{
int status; //存放system函數(shù)的返回值
printf("system函數(shù)調(diào)用date命令.\n");
status = system("date"); //調(diào)用date命令獲得時間相關(guān)信息
if(status <0) //如果status小于0,表明調(diào)用出錯
{
perror("system函數(shù)調(diào)用date出現(xiàn)錯誤.\n"); //調(diào)用出錯
exit(0);
}
printf("system函數(shù)的退出值是%d \n",status); //輸出system函數(shù)的返回值
printf("system函數(shù)調(diào)用nosuchcommand命令.\n");
if((status=system("nosuchcommand"))<0) //如果status為nosuchcommand的返回值
{
printf("system函數(shù)調(diào)用nosuchcommand錯誤");
exit(0);
}
printf("system函數(shù)的退出值是%d \n",status); //打印對應(yīng)狀態(tài)
printf("system函數(shù)調(diào)用who命令\n");
if((status=system("who; exit 44"))<0) //調(diào)用who函數(shù)
{
perror("system函數(shù)調(diào)用who出現(xiàn)錯誤"); //打印錯誤信息
exit(0);
}
printf("system函數(shù)的退出值是%d\n",status); //打印退出狀態(tài)
exit(0);
}
當(dāng)前名稱:[Linux進(jìn)程]system函數(shù)的應(yīng)用
網(wǎng)頁鏈接:
http://weahome.cn/article/gddjii.html