Hi everyone.
I have an external lib that prints some lines with printf.
I'd like to redirect that lines and use them in another function i'm running..
I tried dup2 and pipes with no success..
My goal would be redirecting the stdout to something that could be read with a function like scanf() o read()
What should i do?
Thanks
Last edited on
what i need to do is capture the output printed by printf from a function of an external lib..
i'll try your method
edit:
i don't need/want to use a file..
i need to read from the standard output of a function (that i could call as a new process or thread) in real time in another process/thread
Last edited on
Try something like this:
1 2 3 4 5 6 7 8 9
|
// test.cpp
#include <iostream>
int main() {
std::string s;
while( cin >> s ) {
std::cout << s << std::endl;
}
return 0;
}
| |
The shell handles redirection and piping for you:
$ g++ test.cpp
$ ls | a.out
|
or
Last edited on