Hi i am looking for a way to redirect the output of an exe file that i call within _execl(). (by the way, am i using the _execl() function in the correct way?? ("ARP.exe -a" returns a list of ips connected to the computer over a local network)

CODE so far:

#include <process.h>
using namespace std;
int main()
{
_execl("C:\\Windows\\System32\\ARP.exe", "-a", NULL);
return 0;
}

Here is one way to retired the output of that program to a file. If all you want is to get it into your program then do the same thing here buf save the strings in an array or vector<string>

#include <stdio.h>
#include <iostream>
#include <fstream>
using namespace std;

int main()
{
    char buf[255] = {0};
    FILE* fp = 0;
    fp = _popen("C:\\Windows\\System32\\ARP.exe -a","r");
    if( !fp )
    {
        cout << "_popen() failed\n";
        return 1;
    }
    ofstream out("mel.txt", ios::trunc);
    if( !out.is_open() )
    {
        cout << "can not open mel.txt\n";
        fclose(fp);
        return 1;
    }
    while( fgets(buf, sizeof(buf), fp) != NULL)
        out << buf;
    fclose(fp);
    out.close();
return 0;
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.