c函数中执行shell 命令
2011-12-09 01:03
197 查看
在c函数中执行shell 命令 并获得命令的返回值 #include <stdlib.h> #include <stdio.h> int main(void) { int ret = -1; FILE* pf; /* Can not get the output of the cmd */ ret = system("ls /dev/loop* | wc -l"); printf("ret = %d\n", ret); /* This mothed can get the output of the cmd */ pf = popen("ls /dev/loop* | wc -l", "r"); fscanf(pf, "%d", &ret); printf("ret = %d\n", ret); pclose(pf); return 0; }
相关文章推荐
- shell中的管道命令和并行执行
- ssh远程到目标机器执行命令shell脚本
- Linux下使用popen()执行shell命令
- ASP.NET下使用WScript.Shell执行命令
- Zabbix安全:破解弱口令后执行命令,获取shell
- 执行某个shell命令时出现shell-init的一个错误(目录不存在)
- Linux下使用popen()执行shell命令
- 使用Emacs执行外部shell命令
- 在Jenkins中配置执行远程shell命令(转)
- java 执行shell命令
- Shell简介:什么是Shell,Shell命令的两种执行方式
- 在mysql中执行shell命令
- java模拟ssh执行shell命令
- shell脚本嵌套执行expect命令
- vim中执行shell命令
- shell中命令的执行:$( ) 命令
- awk中可以使用system来执行复杂的shell命令
- ASP.NET下使用WScript.Shell执行命令
- SHELL 如何执行命令
- shell中执行一个字符串命令的方法