1#if (defined __USE_POSIX2 || defined __USE_SVID || defined __USE_BSD || \
2 defined __USE_MISC)
3/* Create a new stream connected to a pipe running the given command.
4
5 This function is a possible cancellation point and therefore not
6 marked with __THROW. */
7extern FILE *popen (const char *__command, const char *__modes) __wur;
8
9/* Close a stream opened by popen and return the status of its child.
10
11 This function is a possible cancellation point and therefore not
12 marked with __THROW. */
13extern int pclose (FILE *__stream);
14#endif
查看源码中的 fgets() 函数原型如下:
1/* Get a newline-terminated string of finite length from STREAM.
2
3 This function is a possible cancellation point and therefore not
4 marked with __THROW. */
5extern char *fgets (char *__restrict __s, int __n, FILE *__restrict __stream)
6 __wur;
4 函数封装
接口 ExecuteCMD() 对于基础的使用已经够了,但是输出结果是 char * 类型的,在 C++ 中实际使用起来不是很方便,为什么不直接转换为 string 类型呢?