系统()输出到一个char * [英] system() output to a char*
本文介绍了系统()输出到一个char *的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
int system(const char *)
我如何发送这个命令的输出(可以说的命令是PWD)为char *?它返回一个int,但我想这个命令的结果发送到一个char *。
How can I send output of this command (lets say the command is "pwd") to a char*? Its returning an int but I want the results of the command to be sent to a char*.
推荐答案
您可以通过管道通过使用PWD>临时文件作为命令的输出直接命令的文件。结果
另一种方法是使用的popen
You can pipe the output of the command directly to a file by using "pwd > tempfile" as command.
Another way is to use popen
FILE *output = popen("pwd", "r");
这会给你一个文件指针,你可以阅读从输出。
That will give you a file pointer where you can read the output from.
这篇关于系统()输出到一个char *的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文