繁体   English   中英

来自C ++代码的Shell命令

[英]Shell command from c++ code

我想为我的Linux脚本创建一个GUI 我以前使用过tk ,但是我不喜欢GUI质量。 这就是为什么我要使用OpenGL创建可以随时间扩展的GUI库的原因。 我的问题是如何从OpenGL C ++代码运行shell命令?

#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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM