-1

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);

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

3
  • Change the file permission with chmod in the system routine? Commented Apr 26, 2013 at 11:32
  • Seems like you want the popen function? Commented Apr 26, 2013 at 11:33
  • duplicate. Please look stackoverflow.com/questions/478898/… Commented Sep 25, 2015 at 8:57

1 Answer 1

1

you can use popen() and then get the output of the command from the pipe opened by popen()

FILE  *fp;
fp=popen("./script.sh","r");

and to get your output. you can use fgets() or fread() to read from pipe like you read from a file

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.