今天才知道 popen 运行一个系统调用时,
通过 popen 返回的文件句柄只能读到系统调用往 stdout 的输出内容。
输出到 stderr 的内容是得不到的。

有一个办法,就是在调用命令的尾部加上 2>&1 这样的内容,
其含义为:将 stderr(2)重定向到 stdout(1)中。

例如 iwconfig eth0 这个命令,如果 eth0 不是无线网卡,运行此命令的后果是得到如下内容

eth0      no wireless extensions.

然而此内容是由 iwconfig 输出到 stderr 中的。
所以如果用 popen("iwconfig eth0", "r") 这样的写法,是无法得到刚才那段内容的。
但如果改成这样调用 popen("iwconfig eth0 2>&1", "r") 的话,
就可以通过 popen 返回的文件句柄读到刚才那段内容了。