How to get output from Linux team via C / C ++? and suitable for android?

I am trying to run a Linux command and read the output from it using C / C ++ code. I am looking for exec, but this is not about I / O.

I am trying to get wireless LAN information using this iwconfig command, calling it from C / C ++ code.

Also I need a suitable code to use it as lib for android using NDK.

I see in the open file open source Android, he called this function

what do you think of 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 a link

+4
source share
2 answers

You can try to run the command and output the results to a file, and then read it

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

I see in the open file open source Android, he called this function

what do you think of 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 a link

0
source

All Articles