用C ++执行脚本 [英] execute script with C++
本文介绍了用C ++执行脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想通过c ++程序执行脚本并获取其输出.目前我正在做
I want to execute a script through a c++ program and get its output. Presently I am doing
system("./script.sh > out.txt");
但是我需要一个将输出转换为字符串的命令,例如:
But I need a command that get the output to a string, some thing like:
out = system("./script.sh");
printf(out);
执行脚本后,我无法读取文件out.txt,因为我对此没有权限.我将c ++程序部署在其他没有该权限的框架(boinc)上.
I can't read the file out.txt after execute the script because I don't have permission to that. I deployed my c++ program at other framework (boinc) that doesn't give me this permission.
有人暗示吗? 提前致谢! 费利佩
Does anybody have a hint? Thanks in advance! Felipe
推荐答案
您可以使用popen()
,然后从popen()
FILE *fp;
fp=popen("./script.sh","r");
并获取您的输出.您可以使用fgets()
或fread()
从管道读取文件,就像从文件中读取文件一样
and to get your output. you can use fgets()
or fread()
to read from pipe like you read from a file
这篇关于用C ++执行脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文