How to redirect output from reading a bash script in c++?
I know that the function:
system("myfile.sh")
exec a bash script. Ok but now I want to redirect the开发者_如何学Python output to my program to ensure the reading. For example the script date.sh give me the date of my system, and i want to see it on my program with std::cout << OUTPUTDATE; Is it possible? How?
Use popen instead of system.
The function popen will give you a FILE * you can read from.
FILE *script = popen("myfile.sh", "r");
while (fgets(line, LENGTH, script)) {
/* ... */
}
pclose(script);
加载中,请稍侯......
精彩评论