[英]Shell command from c++ code
I want to create a GUI
for my linux script. 我想为我的Linux脚本创建一个
GUI
。 I used tk
before but I didn't like the GUI
quality. 我以前使用过
tk
,但是我不喜欢GUI
质量。 That's why I am going to use OpenGL
to create a GUI
lib that I can extend with time. 这就是为什么我要使用
OpenGL
创建可以随时间扩展的GUI
库的原因。 My question is how can I run shell commands from the OpenGL C++ code? 我的问题是如何从OpenGL C ++代码运行shell命令?
system()
function (standard C) system()
函数 (标准C) popen()
function (POSIX) popen()
函数 (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;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.