0

I am having troubles with popen (I am using this on a CentOS machine).

The code is like so (_oss is an ostringstream):

  ...

  FILE*  lp_pipe = popen("/opt/scripts/myscript.php", "r");

  if(!lp_pipe) {
    return false;
  } 

  char l_buffer[256];
  while(!feof(lp_pipe))
  {  
    if(fgets(l_buffer, 256, lp_pipe) != NULL) 
      _oss << l_buffer;
  }

  pclose(lp_pipe);

  ....

Now this was working fine until someone changed the php script. When I run the script from the commandline I still see the expected result, however the code doesn't work anymore. The first time fgets is called it now returns NULL and afterwards feof(lp_pipe) returns 1

Lieuwe
  • 1,734
  • 2
  • 27
  • 41
  • Maybe the script was changed so it's writing to stderr insted of stdout? – Jerry Coffin Jan 15 '13 at 17:33
  • I am no expert in php .. all I can see is that it calls "echo" ... would using 2>&1 in the popen call include stderr? – Lieuwe Jan 15 '13 at 17:35
  • I doubt it would. Before I worried, I'd test on the command line to see if it's writing to stdout, stderr, or both. – Jerry Coffin Jan 15 '13 at 17:37
  • Looking again, I wonder if the problem isn't that somebody removed the lines from the beginning of the script to say that it needs to invoke the PHP executable to run the script. – Jerry Coffin Jan 15 '13 at 17:40
  • I found out what it was. My nice colleague changed the file permissions for the php file. I could read it (from the commandline) but the C++ program I built couldn't. I am sorry to have troubled you but thanks for thinking! – Lieuwe Jan 15 '13 at 17:43

0 Answers0