如何在Ubuntu中使用C语言的命令终端
How to using command terminal in C in Ubuntu
我想在文件夹中复制一个文件,我想写一个函数来计算还有多少文件需要复制。
我可以用两个命令在终端中实现它。
第一个命令将获取文件夹中的所有文件-在处理
之前 find . -type f | wc -l
=> counter1
-原始文件数
第二个命令将获取当前文件夹中已经存在的所有文件。
find . -type f | wc -l
=> counter2
-原文件编号+复制文件
file_remaining = counter1 * 2 - counter2
counter1
乘以2因为我想复制一个文件
如何在Ubuntu终端中使用C或c++编写一个函数来获取这两个命令的信息?
这就是我的答案。如果你不明白我的问题,请不要回答
#include <iostream>
#include<stdio.h>
using namespace std;
int main( int argc, const char * argv[] )
{
FILE * fp ;
char tstCommand[] ="find . -type f | wc -l";
char path[100];
fp = popen(tstCommand, "r");
while ( fgets( path, 100, fp ) != NULL )
cout << path << endl;
pclose(fp);
return 0;
}
相关文章:
- 从命令行c++发送文本文件名
- 如何使用 < 和 > 命令获取 c++ 中的输入和输出?
- 为cl.exe(Visual Studio代码)指定命令行C++版本
- 如何在OMNET++中指定与命令行参数组合的输出文件名
- 使用QProcess执行命令,并将结果存储在QStringList中
- 数组长度,为什么从命令行获取时不能使用它?
- 如果用户输入无效,如何使用字符串变量-C++重复输入命令
- clang整洁10忽略了我的NOLINT命令
- 不同语言中相同代码的不同行为
- 在子目录中使用target_sources()命令时用于单元测试(qtest)的项目结构
- 如何处理linux终端中带有负号(-)的C++中的命令行参数
- VS Code "command":"make"与终端窗口中的命令行"make"不同
- 使用VS Code和CMake Tools运行自定义命令
- 如何使用ESP8266向谷歌主页发送命令
- 如何使 windows 命令提示符在C++可执行文件上显示返回值?
- 如何用c语言翻译openssl命令pbkdf2
- Blender语言 - C# C++中的命令
- 如何在C语言中以确定的概率处理命令?
- Gstreamer语言 - 转换命令行gst-launch到C代码
- 如何在Ubuntu中使用C语言的命令终端