I try to run a Linux command and read the output from it by using C/C++ code.
I search for exec but this don't deal with input/output.

What I am trying to achieve is to get information about wireless LAN by using this command `iwconfig`, invoking it from C/C++ code.

also i need a suitable code to use it as lib for android using NDK.

i see in android open source they called this function

what do you think about this code ?

```
int wpa_ctrl_request(struct wpa_ctrl *ctrl, const char *cmd, size_t cmd_len,
                 char *reply, size_t *reply_len,
                 void (*msg_cb)(char *msg, size_t len))
                {
        DWORD written;
        DWORD readlen = *reply_len;

if (!WriteFile(ctrl->pipe, cmd, cmd_len, &written, NULL))
    return -1;

if (!ReadFile(ctrl->pipe, reply, *reply_len, &readlen, NULL))
    return -1;
*reply_len = readlen;

return 0;

```

}

this is the  [link](http://androidxref.com/4.2_r1/xref/external/wpa_supplicant_6/wpa_supplicant/src/common/wpa_ctrl.c#505)
['https://Stackoverflow.com/questions/15164450', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/2110922/']
You could try running the command and outputting the results to a file, then reading it

```
system("iwconfig > temp.txt");
FILE *fp=fopen("temp.txt","w");

```
i see in android open source they called this function 

what do you think about this code ?

```
int wpa_ctrl_request(struct wpa_ctrl *ctrl, const char *cmd, size_t cmd_len,
                     char *reply, size_t *reply_len,
                     void (*msg_cb)(char *msg, size_t len))
{
    DWORD written;
    DWORD readlen = *reply_len;

    if (!WriteFile(ctrl->pipe, cmd, cmd_len, &written, NULL))
        return -1;

    if (!ReadFile(ctrl->pipe, reply, *reply_len, &readlen, NULL))
        return -1;
    *reply_len = readlen;

    return 0;
}

```

this is the  [link](http://androidxref.com/4.2_r1/xref/external/wpa_supplicant_6/wpa_supplicant/src/common/wpa_ctrl.c#505)