I'm new here so forgive me if I post my question in the wrong place. Part of one of my programs filters the CMD output of "netsh wlan show networks bssid" into a txt file on my desktop, before using fstream to read each string of the file, pushing back each string into a vector of strings, and then deleting the txt file on the desktop before continuing. Here is an example:
#include <iostream>
#include <fstream>
#include <vector>
using namespace std;
int main()
{
string cmd_output;
vector<string> output;
fstream search;
system("netsh wlan show networks bssid > cmd_output.txt");
search.open("cmd_output.txt", ios::in);
while (search >> cmd_output)
output.push_back(cmd_output);
search.close();
system("del cmd_output.txt");
//program continues..
return 0;
}
Now ... If I wanted to simply filter the CMD output into a vector (without creating any txt files), how might I go about doing that? I've tried declaring variables and assigning the system calls to them but that doesn't work.
How might one go about trying something like ...
string cmd_output = system("netsh wlan show networks bssid"); ... ?
How might one go about trying something like ...
string cmd_output = system("netsh wlan show networks bssid"); ... ?
The system() function has no such capability. The function you're looking for is the POSIX function popen(). The boost library collection recently got a very convenient iostreams-based wrapper around it, see boost.process http://www.boost.org/doc/libs/1_64_0/doc/html/process.html