-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

Knoblauch
  • 5,740
  • 6
  • 33
  • 81

1 Answers1

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

MOHAMED
  • 38,769
  • 51
  • 148
  • 252