gpt4 book ai didi

c++ - C++ 中的 Bash 输入/输出

转载 作者:塔克拉玛干 更新时间:2023-11-03 01:32:58 25 4
gpt4 key购买 nike

我正在用 C++ 编写程序(用于 XAMPP 通信),我想执行我在字符串中的命令(我知道这只是 system("command")),但我想从 bash 获取输出到C++ 到字符串。我已经建立了几个关于这个的线程,但没有一个解决了 Bash -> C++。

最佳答案

您可以调用 FILE *popen(const char *command, const char *mode) 函数。然后,您可以读取它返回的文件以获取调用的输出。

这就像使用管道将您使用的命令的输出重定向到硬盘中的文件,然后读取该文件,但您并没有在硬盘中创建文件。

The documentation of the popen() is here.

关于c++ - C++ 中的 Bash 输入/输出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1517084/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com