linux下c调用shell命令,以及判断文件是否存在
来源:互联网 发布:画苯环的软件 编辑:程序博客网 时间:2024/06/18 16:37
1. linux下c调用shell命令的方法
方法:使用 popen() 函数 ,需要包含头文件 #include <stdio.h>
代码如下:
#include <stdio.h>#include <stdlib.h>#include <iostream>using namespace std;int main(void){ FILE *fp; fp = popen("ls /home", "w"); if (NULL == fp) { cout << "error" << endl; } pclose(fp); return 0;}
2. 检查文件是否存在
方法: 使用access() 函数,需要包含头文件 #include <unistd.h>
代码如下:
#include <stdio.h>#include <stdlib.h>#include <iostream>#include <unistd.h>using namespace std;int main(void){ if (access("/home/1.txt", F_OK) == -1) { cout << "不存在" << endl; } return 0;}
access() 函数:
存在,返回0 ;
不存在,返回-1
---
0 0
- linux下c调用shell命令,以及判断文件是否存在
- Linux Shell命令中判断目录下是否存在已知后缀名文件的命令
- Linux Shell命令中判断目录下是否存在已知后缀名文件的命令
- Linux shell判断文件是否存在
- linux shell 判断文件是否存在
- linux shell 判断文件是否存在
- Linux shell判断文件是否存在
- linux C判断文件是否存在
- linux C判断文件是否存在
- linux C判断文件是否存在【转】
- Linux c判断文件是否存在
- shell判断文件是否存在
- Shell--判断文件是否存在
- shell判断文件是否存在
- shell判断文件是否存在
- shell判断文件是否存在
- shell 判断文件是否存在
- shell 判断文件是否存在
- 关于linux中消息队列的使用
- oracle11g数据库如何正确导入dmp文件数据
- Leetcode-DSF-Scramble String
- VS2010 编写程序在其他系统上退出奔溃问题
- 23种设计模式之原型模式
- linux下c调用shell命令,以及判断文件是否存在
- Elasticsearch 集群优化篇
- make的简单应用笔记
- ORACLE 创建视图时,提示用户权限不足
- Web里面的文件上传
- Tomcat启动找不到maven里的类 抛ClassNotFoundException
- shell脚本学习
- Codeforces 799C Fountains 枚举+二分
- 蓝桥杯 反幻方