Search code examples
c++streamexecuname

Good way to send result of 'uname -a' to a stream?


What is a good way to call 'uname -a' from a C++ program and send the results to a stream?

I looked at system() and exec(), but they do not seem to give access to the stdout of the call.

Thanks.

-William


Solution

  • Why not just retrieve the strings directly from the struct utsname returned from the uname(2) system call found on most Unix/Unix-like platforms?

    No need to fork a "uname -a" process.