【发布时间】:2014-01-20 21:11:21
【问题描述】:
我想为我的 linux 脚本创建一个GUI。我以前用过tk,但我不喜欢GUI 的质量。这就是为什么我要使用OpenGL 创建一个可以随时间扩展的GUI 库。
我的问题是如何从 OpenGL C++ 代码运行 shell 命令?
【问题讨论】:
标签: c++ linux opengl user-interface
我想为我的 linux 脚本创建一个GUI。我以前用过tk,但我不喜欢GUI 的质量。这就是为什么我要使用OpenGL 创建一个可以随时间扩展的GUI 库。
我的问题是如何从 OpenGL C++ 代码运行 shell 命令?
【问题讨论】:
标签: c++ linux opengl user-interface
system() function(标准 C)popen() function (POSIX)【讨论】:
#include <string>
#include <iostream>
#include <stdio.h>
const std::string exec(const std::string& cmd) {
FILE* pipe = popen(cmd.c_str(), "r");
if (!pipe) return "ERROR";
char buffer[128];
std::string result;
while(!feof(pipe)) {
if(fgets(buffer, 128, pipe) != NULL)
result += buffer;
}
pclose(pipe);
return result;
}
【讨论】: