C语言中 使用popen函数向linux系统发送shell命令
来源:互联网 发布:return java 编辑:程序博客网 时间:2024/06/07 01:57
头文件:
stdio.h
stdio.h
函数原型:
FILE *popen(const char *command,const char *type);
FILE *popen(const char *command,const char *type);
参数说明:
command存放要发送的命令
type值如果是r,那么标准输出;如果是w,那么标准输入。
command存放要发送的命令
type值如果是r,那么标准输出;如果是w,那么标准输入。
举例:
#include<stdio.h>
int main()
{
FILE *stream; //存放文件流指针
char command[100]="ls"; //打印当前目录下的文件及文件夹
char result[100]={0}; //存放结果
stream = popen(command,"r"); //发送命令
if(!stream)
{
printf("error\n");
}
fread(result,1,100,stream); //读取查询结果
if(result = NULL)
{
printf("error or NULL\n");
}
pclose(stream);
return 0;
}
#include<stdio.h>
int main()
{
FILE *stream; //存放文件流指针
char command[100]="ls"; //打印当前目录下的文件及文件夹
char result[100]={0}; //存放结果
stream = popen(command,"r"); //发送命令
if(!stream)
{
printf("error\n");
}
fread(result,1,100,stream); //读取查询结果
if(result = NULL)
{
printf("error or NULL\n");
}
pclose(stream);
return 0;
}
阅读全文
0 0
- C语言中 使用popen函数向linux系统发送shell命令
- linux c之通过popen和pclose函数创建管道执行shell 运行命令使用总结
- C程序获取shell脚本命令输出,使用popen()函数
- C语言中调用系统命令(system popen...)
- linux c语言 system系统调用与popen的使用
- 使用popen函数执行shell命令
- Linux下使用popen()执行shell命令
- Linux下使用popen()执行shell命令
- Linux下使用popen()执行shell命令
- Linux下使用popen()执行shell命令
- Linux下使用popen()执行shell命令
- Linux下使用popen()执行shell命令
- Linux下使用popen()执行shell命令
- C语言popen创建管道文件循环执行shell命令
- linux下C和shell调用的popen函数
- linux下C和shell调用的popen函数
- linux下C和shell调用的popen函数
- linux下C和shell调用的popen函数
- java使用itext按页码拆分pdf
- binary
- six
- 彻底理解Redis有效期问题
- c++ 学习笔记
- C语言中 使用popen函数向linux系统发送shell命令
- POJ 3268 Silver Cow Party 最短路 dijkstra
- dows命令安装pymysql 和 Django
- 实体标签
- 操作系统复习-3.2覆盖与交换
- 遇到的问题
- 软件工程要点整理
- Android 手机6.0 定位权限问题
- Hadoop-Streaming实战经验及问题解决方法总结