0

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;
}
2
Contributors
1
Reply
2
Views
8 Years
Discussion Span
Last Post by Ancient Dragon
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;
}
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.