I just want to know which is the best way to execute an external command in C++ and how can I grab the output if there is any?
Edit: I Guess I had to tell that I'm a newbie here in this world, so I think I'm gonna need a working example. For example I want to execute a command like:
ls -la
how do I do that?
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);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With