#include <stdio.h>
#include <iostream>
#include <string>
using namespace Std;
Description: The Execmd function executes the command and stores the result in the results string array
Parameter: cmd indicates the command to execute
Result is an array of strings that execute the resulting store
function execution successfully returns 1, failure returns 0
int Execmd (char* cmd,char* result) {
Char buffer[128]; Defining buffers
file* pipe = _popen (cmd, "R"); Open the pipeline and execute the command
if (!pipe) return 0; Returning 0 indicates a failed run
while (!feof (pipe)) {
if (fgets (buffer, line, pipe)) {//pipe is output to result
strcat (Result,buffer);
}
}
_pclose (pipe); Close pipe
return 1; Returning 1 indicates a successful run
}
int main () {
Char result[1024*4]= ""; Defines a string array that holds the result
if (1==execmd ("rasdial", result)) {
printf (result);
cout<<result;
}
System ("pause"); Pause to view results
}
C + + to get cmd output characters through pipe pipes