C ++ system()函数 - 如何收集已发出命令的输出? [英] C++ system() function — How to collect the output of the issued command?

查看:238
本文介绍了C ++ system()函数 - 如何收集已发出命令的输出?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用C ++ system()函数运行一些命令:

I'm running some commands with the C++ system() function:

int system ( const char * command );

如何从发出的命令收集标准输出?

How can I collect the standard output from the issued commands?

具体来说,我想收集发出的命令的输出(例如,发出 dir

To be specific, I want to collect the output of the issued command (for example, the directory listing output from issuing the dir command).

推荐答案

如果后者,请使用 popen() pclose()

If the latter, use popen() and pclose() instead.

如果是前者,请查看 system()的返回值(并使用 waitpid() 信息来解释它)。

If the former, look at the return value from system() (and use the information from the waitpid() information to interpret it).

这篇关于C ++ system()函数 - 如何收集已发出命令的输出?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆