我試圖運行命令ifconfig wlan0 up
並通過以下方式獲得此命令的結果:Linux下C/C++:獲取使用ifconfig爲wlan0了輸出
std::string exec(char* cmd)
{
FILE* pipe = popen(cmd, "r");
if (!pipe) return "ERROR";
char buffer[128];
std::string result = "";
while(!feof(pipe) )
{
if(fgets(buffer, 128, pipe) != NULL)
result += buffer;
}
pclose(pipe);
return result;
}
但是,調用與ifconfig wlan0 up
上述功能時它會返回空結果(儘管命令成功)。
預期結果(從命令提示符下運行時):
[ 68.126342] wl12xx: state: 0
[ 68.683715] wl12xx: firmware booted (Rev 6.3.10.0.135)
任何想法? 謝謝!
是不是想要的結果? AFAIK它不會在工作時發出喋喋不休的聲音。 – 2014-10-07 11:15:35
是否將結果寫入ifconfig的標準輸出? – whoan 2014-10-07 11:36:15