I need to run RNAeval (executable) from a c++ code and read the output of RNAeval
. I found a code which can run a command and read the output.
string exec(char* cmd) {
FILE* pipe = popen(cmd, "r");
if (!pipe) return "ERROR";
char buffer[128];
std::string result = "";
while(!feof(pipe)) {
if(fgets(buffer, 128, pipe) != NULL)
result += buffer;
}
pclose(pipe);
return result;
}
But RNAeval doesn't take any command line argument. Instead i need to provide input after run the program (similar to bc
in linux).
example
RNAeval [enter]
input1 [enter]
input2 [enter]
return output by RNAeval and exit
How can i do this from c++?
System:
Linux
g++
gcc
Edit
string exec(char* cmd) {
FILE* pipe = popen(cmd, "w");
if (!pipe) return "ERROR";
char buffer[128];
std::string result = "";
fprintf(pipe,"%s\n","acgt");
fprintf(pipe,"%s\n","(())");
fprintf(pipe,"%s\n","@");
while(!feof(pipe)) {
if(fgets(buffer, 128, pipe) != NULL)
result += buffer;
}
pclose(pipe);
return result;
}