Capture the output from an exe

im writing a small editor for RSL coding, and ive got an external program "3Delight" to compile the code.

Now i want the output from that exe to be captured in a string once the compilation is comlete, but all of the methods ive found online dont seem to work for me. Ive tried using _popen which works if i run a normal command like "dir", but not with the exe.

This is the function ive been using that works with the normal commands

1
2
3
4
5
6
7
8
9
10
11
12
13
std::string exec(const char* cmd) 
{
    FILE* pipe = _popen(cmd, "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;
}


and this is how i was calling it, but it just returned an empty string, even though the exe printed "Compilation successful"

exec("\"\"%DELIGHT%/bin/shaderdl\" \"E:/RenderManShaders/TestArea/Source/basicDiffuse.sl\"")

any help?
cheers
Last edited on
closed account (ypfz3TCk)
I would say that the problem is in line 8. That condition is never satisfied so nothing is ever passed to the string result.
do you mean that only when the command shown is used, or when any command is used?

i only ask because all of windows normal shell commands return results, its only when i run the exe that the output is empty

maybe im just using it wrong, im new to this kinda stuff and though it would be a little different
Do you just want to redirect stdout?
1
2
3
4
5
6
#include <cstdio>
int main()
{
    std::freopen("myfile.txt", "w", stdout);
    std::system("help");
}
Topic archived. No new replies allowed.