【问题标题】:Shell command from c++ code来自 C++ 代码的 Shell 命令
【发布时间】:2014-01-20 21:11:21
【问题描述】:

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

【问题讨论】:

    标签: c++ linux opengl user-interface


    【解决方案1】:

    【讨论】:

      【解决方案2】:
      #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;
      }
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2023-03-23
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2012-01-15
        • 1970-01-01
        相关资源
        最近更新 更多