C++ system() function — How to collect the output of the issued command?

前端 未结 8 1697
暖寄归人
暖寄归人 2020-12-03 16:14

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

int system ( const char * command );

How can I collect the standard

8条回答
  •  星月不相逢
    2020-12-03 16:58

    The return value of system is (ironically) system-dependent, but in POSIX systems (including Linux, etc), it's the same as for wait -- low 8 or 16 bits are the exit status of the child (probably what you mean by "value returned by"), higher bits indicating what kind of signal terminated the child, if any. The URL to the manpage I've given supplies the preprocessor macros you can use to pry apart that return value!

    There is no such thing as a "return string" of a program, as you've now clarified in a comment is what you desire; as another answer already mentioned, if you want the text which gets output by the other program, you should use popen instead of system.

提交回复
热议问题