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

前端 未结 8 1667
暖寄归人
暖寄归人 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 17:04

    Are you looking for returned value (as in "exit status") of the executed command, or for its output (as in "what did it print")?

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

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

    0 讨论(0)
  • 2020-12-03 17:05

    I suggest the popen() functions, as said by other people as well, but this problem is platform specific. the popen() function is available on operating systems that use the POSIX API. I am not sure if this command would work on other APIs like WIN32

    0 讨论(0)
提交回复
热议问题