In c++, I want to send a command to the terminal(system()
) and then send whatever output the terminal shows into a variable, but I don't know how. I'm aware of the std::getline()
function, but I'm not sure that would do the trick. If you know a way to complete this task, please let me know. Thanks in advance.
Asked
Active
Viewed 51 times
0

sharpcdf
- 5
- 1
- 5
-
Tricky. `system` is too stupid for what you want because it doesn't give you access to the console output of the program run by `system`. In a POSIX system you'd use `popen`. Not sure what you use in Windows. Once you have the console output, you parse it and grab the data you need. I recommend adding your target operating system so people can point you at the right functions and a sample of the console output you need parsed so people can help out with that as well. At the moment this question cannot be fully answered. – user4581301 May 13 '21 at 23:57
-
`popen()` plus a little magic. It's all about pipes. – tadman May 14 '21 at 00:05