VS2019 popen不使用环境变量

VS2019 popen not using environment variables

我试图在我的 VS 项目中执行某种 eval 命令,但我遇到了一个错误。这是我的代码:

#include <iostream>
#include <stdexcept>
#include <stdio.h>
#include <string>
#include <fstream>
using string = std::string;

string eval(string cmd) {
    std::ofstream ree;
    ree.open("WRITEFILE.cpp", std::ofstream::out | std::ofstream::trunc);
    ree << cmd;
    ree.close();
    char buffer[128];
   string result = "";
   const char* cmdstr = "g++ WRITEFILE.cpp -o WRITE.exe && WRITE.exe"; // + libraries once I get it working
   std::cout << cmdstr;
   FILE* pipe = _popen(cmdstr, "r");
   if (!pipe) {
      return "popen failed!";
   }
  while (!feof(pipe)) {

  // use buffer to read and add to result
  if (fgets(buffer, 128, pipe) != NULL)
     result += buffer;
   }

   _pclose(pipe);
   return result;
} 

我的 Path 环境变量包括我的 mingw bin 目录以及我存储所有库的文件夹;但是我收到错误 'g++' is not recognized as an internal or external command.' 此外,如果我用完整路径替换 g++,它不会在同一文件夹中找到库。我知道这不是环境变量问题,因为我在所有较小的项目中都使用 G++(这个项目无法使用)并且没有遇到任何问题。我不确定现在该去哪里,所以感谢您的帮助

You can inspect the PATH environment variable by clicking properties on your project then Debugging -> Environment then Edit and type $(Path) in the top window of the popup. Visual Studio 2019 will show the value of the PATH environment being sent to application when it will be debugged in the Visual Studio Community / Enterprise or Pro. Thanks to @dresherjm