[英]How to implement shell output as a input of C language?
For example, Guess I have a compiled c program, named as 'binaryOutput'. 例如,猜猜我有一个已编译的c程序,名为“ binaryOutput”。 And in Unix environment, [root@blablabla ~ ] ./binaryOutput print out some result like this [0] [1] [0] [1] [1]
在Unix环境中,[root @ blablabla〜] ./binaryOutput打印出如下结果:[0] [1] [0] [1] [1]
I want to using these result as the input of another c file. 我想将这些结果用作另一个C文件的输入。
In C lanugage, I can run the file. 在C语言中,我可以运行文件。
system("./binaryOutput") ;
After the code, I want to add the numbers as an array's input. 在代码之后,我想将数字添加为数组的输入。 How can I do it?
我该怎么做?
popen example. popen示例。 You can get the output of the command.
您可以获取命令的输出。
#include <stdio.h>
int main(void)
{
FILE *fp=NULL;
char line[1024];
if ( (fp=popen("ls", "r"))==NULL )
{
return -1;
}
while( fgets(line, 1023, fp)!=NULL )
{
printf("read from popen:%s", line);
}
pclose(fp);
return 0;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.