Bash input/output in C++

I'm writing program in C++ (for XAMPP communication) and I want to execute command which I have in strings (I know that this is simply system("command")) but I want to get the output from bash to C++ to string. I've founded several threads about this, but no which solved Bash -> C++.


You can call the FILE *popen(const char *command, const char *mode) function. Then, you can read the file it returns to get the output of your call.

It's like using a pipe to redirect the output of the command you used to a file in the hard drive and then read the file, but you don't get to create a file in the hard drive.

The documentation of the popen() is here.


您需要调用popen函数,并从它返回的FILE中读取输出。


You can try Standard Output Redirection to redirect the standard output to a file stream and then use it to read to a string.

Dup()

链接地址: http://www.djcxy.com/p/74848.html

上一篇: 如何正确使用system()在C ++中执行命令?

下一篇: Bash输入/输出在C ++中