小白教程
所有教程
关于
Search
172.70.131.96
172.70.131.96
参数设置
贡献
退出
操作
编辑
移动
保护
信息
历史
删除
查看“C function system”的源代码
本页内容
上一节:
C_function_getenv
下一节:
C_function_bsearch
因为以下原因,您没有权限编辑本页:
您请求的操作仅限属于该用户组的用户执行:
用户
您可以查看和复制此页面的源代码。
{{DISPLAYTITLE:int system(const char *string)}}[[Category:c standard library stdlib h|15]] = C 库函数 - system() = [[c standard library stdlib h|C 标准库 - <stdlib.h>]] == 描述 == C 库函数 '''int system(const char *command)''' 把 '''command''' 指定的命令名称或程序名称传给要被命令处理器执行的主机环境,并在命令完成后返回。 == 声明 == 下面是 system() 函数的声明。 <pre> int system(const char *command) </pre> == 参数 == * '''command''' -- 包含被请求变量名称的 C 字符串。 == 返回值 == 如果发生错误,则返回值为 -1,否则返回命令的状态。 下面的实例演示了 system() 函数的用法,列出了 unix 机上当前目录下所有的文件和目录。 <sample title="" desc="" lang="c" hererun="1"> #include <stdio.h> #include <string.h> #include<stdlib.h> int main () { char command[50]; strcpy( command, "ls -l" ); system(command); return(0); } </sample> 让我们编译并运行上面的程序,在 unix 机上将产生以下结果: <pre> drwxr-xr-x 2 apache apache 4096 Aug 22 07:25 hsperfdata_apache drwxr-xr-x 2 railo railo 4096 Aug 21 18:48 hsperfdata_railo rw------ 1 apache apache 8 Aug 21 18:48 mod_mono_dashboard_XXGLOBAL_1 rw------ 1 apache apache 8 Aug 21 18:48 mod_mono_dashboard_asp_2 srwx---- 1 apache apache 0 Aug 22 05:28 mod_mono_server_asp rw------ 1 apache apache 0 Aug 22 05:28 mod_mono_server_asp_1280495620 srwx---- 1 apache apache 0 Aug 21 18:48 mod_mono_server_global </pre> 下面的实例演示了 system() 函数的用法,列出了 windows 机上当前目录下所有的文件和目录。 <pre> #include <stdio.h> #include <string.h> int main () { char command[50]; strcpy( command, "dir" ); system(command); return(0); } </pre> 让我们编译并运行上面的程序,在 windows 机上将产生以下结果: <pre> a.txt amit.doc sachin saurav file.c </pre> [[c standard library stdlib h|C 标准库 - <stdlib.h>]]
返回至“
C function system
”。
上一节:
C_function_getenv
下一节:
C_function_bsearch