interactive - Run program from c++ source which required multiple input -


i need run rnaeval (executable) c++ code , read output of rnaeval. found code can run command , read 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 command line argument. instead need provide input after run program (similar bc in linux).

example

rnaeval [enter] input1 [enter] input2 [enter] return output rnaeval , exit 

how can 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;  } 

popen returns file object use write rnaeval's input stream. can use fprintf write commands process after popen, read in results.


Comments

Popular posts from this blog

php - regexp cyrillic filename not matches -

c# - OpenXML hanging while writing elements -

sql - Select Query has unexpected multiple records (MS Access) -