2014-01-20 66 views
0

我想爲我的linux腳本創建一個GUI。我之前使用過tk,但我不喜歡GUI質量。這就是爲什麼我要用OpenGL創建一個GUI庫,我可以隨着時間的推移。 我的問題是如何從OpenGL C++代碼運行shell命令?來自C++代碼的shell命令

回答

0
#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; 
}