views:

128

answers:

3

Hello,

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

+2  A: 

See here http://stackoverflow.com/questions/300669/launch-app-capture-stdout-and-stderr-in-c for a possible way.

Preet Sangha
I was hoping for something simpler than popen() but will use that as it appears that's the only way.
WilliamKF
A: 

Another option (if you are using Qt) is to use QProcess.

larsm
+1  A: 

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.

Void