Advertisement
nordlaender

Popen

Aug 21st, 2016
419
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.90 KB | None | 0 0
  1. //
  2. // Created by lhk on 21.08.16.
  3. //
  4.  
  5. #include "urho_popen.h"
  6.  
  7. void get_pT_urho_popen(const double& u, const double& rho, double& p, double& T){
  8.     FILE *in;
  9.     char buff[512];
  10.  
  11.  
  12.     //const char* command=("Python/python3 piap.py "+ to_string(u)+" "+to_string(rho)).c_str();
  13.     //cout<< "command for subprocess: "<<command<<endl;
  14.  
  15.     ostringstream command;
  16.     command<<"cd ; python3 piap.py "<<u<<" "<<rho;
  17.     cout<<"command for subprocess: "<<command.str()<<endl;
  18.     if(!(in = popen(command.str().c_str(), "r"))){
  19.         cout<<"some problem with the subprocess"<<endl;
  20.     }
  21.     double data[2];
  22.     int idx=0;
  23.  
  24.     cout<<"ran the subprocess"<<endl;
  25.     while(fgets(buff, sizeof(buff), in)!=NULL){
  26.         data[idx] = atof(buff);
  27.         cout <<data[idx]<<endl;
  28.         idx++;
  29.         cout <<"new line"<<endl;
  30.     }
  31.     pclose(in);
  32.  
  33.     p=data[0];
  34.     T=data[1];
  35.     return;
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement