使用system函数

来源:互联网 发布:路由器流量控制软件 编辑:程序博客网 时间:2024/05/19 17:07
system函数声明为:  int system(const char *string);string为你要输入的命令。  实例如下:/* * Demonstrate the system() call */#include <stdio.h>#include <stdlib.h>int main(){int retval;//retval is the return value of the system callretval = system("ls -l");if(retval == 127){fprintf(stderr, "/bin/sh not available\n");exit (127);}else if(retval == -1){perror("system");exit(EXIT_FAILURE);}else if(retval != 0){fprintf(stderr, "command returned %d\n", retval);perror("ls");}else{puts("command successfully executed");}return (0);}