c++ - popen on process with no output -
I have this code, I try to open a process with Papen, get my output and after After every four, I check with the Proc that if some time has passed and if I leave the truth and stop the process, the problem is that if there is no output in the process of any reason, but Open and running, so do me anytime Class time will not get a chance to finish, so that the loop shall not be out. How can any suggestions be resolved?
four buffers [1024]; FILE * proc; // us a file descriptor for process proc = popen (commandLine.c_str (), "r"); // We never do pipe data in spanded processes, so the second parameter is always "R" if (! Proc) Return -1; // If this does not work then we come back std :: time_t startTime = std :: time (NULL); While (! F) {if (fgets (buffer, 1, proc)! = NULL) // There is nothing to read, until {output-> Attachment (buffer); Std :: time_t currTime = std :: time (NULL); Int seconds = std :: difftime (currTime, startTime); If break (sec & gt; = expired) break; } And break; } Int closeFd = pclose (proc); Int exitCode = WEXITSTATUS (closeFd); Return exitcode;
Comments
Post a Comment