Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

c++

popen

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?

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

like image 289
mspoerr Avatar asked Nov 27 '22 08:11

mspoerr


1 Answers

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 documentation for waitpid() to interpret it).

like image 126
Employed Russian Avatar answered Dec 21 '22 09:12

Employed Russian