As @SGrebenkin mentioned, system
should redirect any output of the commands to stdout, unless they are redirected to somewhere else.
While the accepted answer suggested popen
, it is worth mentioning that popen
on windows might have unwanted side effects, especially for GUI applications.
If used in a Windows program, the _popen function returns an invalid
file pointer that causes the program to stop responding indefinitely.
_popen works properly in a console application.
There's a library that can capture the output of a command, and can then be output to stdout with printf
.
https://github.com/Neko-Box-Coder/System2
It works for posix and windows systems. (It doesn't use popen for windows so it should also work in GUI applications)
It can send input and receive output from command.
And have blocking and non-blocking version.
And it has both header only and source version as well
system()
function uses the command interpreter to run the argument string of thesystem()
function so it may be that the command interpreter is not inheriting your standard out so the output from the command is not going to the console window. Another thing may be that the commands you are using are not generating any output. try a different command such as theecho
command so do something likesystem("echo this is output")
. – Stencilset
-ing (orcd
) with one call tosystem
would affect the next call tosystem
(on POSIX & Linux, I am sure it does not work. But I don't know Windows). – Ermeenasystem
? Or use some framework like POCO, Qt, or perhaps Boost. – Ermeena