Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

error C3861: popen, pclose: identifier not found in c++

I get the error "error C3861: popen: identifier not found", if I run through vs code then everything works, but if I run through microsoft vs then the program does not want to compile. How to fix it?

code (c++):

#include <iostream>
#include <string>
#include <cstdlib>

int main() {
    std::string result = "";

    FILE* pipe = popen("some command 2>&1", "r"); //error

    char buffer[128];
    while(!feof(pipe)) {
        if(fgets(buffer, 128, pipe) != NULL)
            result += buffer;
    }
    pclose(pipe); //error

    std::cout << "res :" << result;
    return 0;
}

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

If you are on Windows, it might be _popen() and _pclose()

Try this:

FILE* pipe = _popen("some command 2>&1", "r");
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading