Use the popen
function.
Example (not complete, production quality code, no error handling):
FILE* file = popen("ls", "r");
// use fscanf to read:
char buffer[100];
fscanf(file, "%100s", buffer);
pclose(file);
More Related Contents:
- some problems about c++ try catch [closed]
- How do I find the location of the executable in C? [duplicate]
- print call stack in C or C++
- C++ Dynamic Shared Library on Linux
- How to get memory usage at runtime using C++?
- How can I create directory tree in C++/Linux?
- C++ cross-compiler from Windows to Linux [closed]
- How to create a single instance application in C or C++
- Send and Receive a file in socket programming in Linux with C/C++ (GCC/G++)
- Seeking and reading large files in a Linux C++ application
- How to disassemble a binary executable in Linux to get the assembly code?
- Cancelling a thread using pthread_cancel : good practice or bad
- Linking libstdc++ statically: any gotchas?
- How to set up googleTest as a shared library on Linux
- C++ new operator thread safety in linux and gcc 4
- How to programmatically cause a core dump in C/C++
- Linking g++ 4.8 to libstdc++
- How to pretty-print STL containers in GDB?
- Could you recommend some guides about Epoll on Linux [closed]
- How to define a string literal in gcc command line?
- Command working in terminal, but not via QProcess
- C and C++ programming on Ubuntu 11.10 [closed]
- “relocation R_X86_64_32S against ” linking Error
- Ctrl + C interrupt event handling in Linux
- C++ Socket Server – Unable to saturate CPU
- How to perform atomic operations on Linux that work on x86, arm, GCC and icc?
- Large 2D array gives segmentation fault
- _GLIBCXX_USE_CXX11_ABI, GCC 4.8 and ABI compatibility
- Getting another process command line in Windows
- On OS X, simple C++ program gives incorrect results (which are a result of command-line options ‘c++03’ vs ‘c++11’)