Poco Process correct usage?

Please post support and help requests here.
francisr
Posts: 21
Joined: 09 Dec 2007, 13:19

Poco Process correct usage?

Postby francisr » 21 Nov 2008, 23:24

I have been trying to use the Poco Process classes to launch a process and read both the input and error streams. This usually works, however sometimes the loop stops forever at one of the calls to istream's get method. This only happens if I read both the output and error pipes. If I only read the input pipe the error does not occur.

I wonder if I am doing something wrong. Here is a piece of my code:

Code: Select all


Pipe outPipe;
Pipe errPipe;
ProcessHandle ph = Process::launch(mMPlayerPath, args, 0, &outPipe, &errPipe);
std::string outString;
std::string errorString;
PipeInputStream istr(outPipe);
PipeInputStream error_istr(errPipe);
bool keepGoing = true;

while (keepGoing)
{
   int c = istr.get();
   if (c != -1)
   {
      outString += (char) c;
   }

   int e = error_istr.get();
   if (e != -1)
   {
      errorString += (char)e;
   }

   keepGoing = ((c != -1) || (e != -1));
}


Can anyone point me out my error? I think the problem is not in Poco because I've had the same problem occur when using Cocoa's NSTask.

Thanks!

Francis

alex
Posts: 1246
Joined: 11 Jul 2006, 16:27
Location: United_States

Re: Poco Process correct usage?

Postby alex » 22 Nov 2008, 04:02

> Can anyone point me out my error? I think the problem is not in Poco because I've had the same problem occur when using Cocoa's NSTask.

Then you should look into what the process is doing. You can also add additional check prior to reading:

Code: Select all


while (keepGoing)
{
   int c = -1;
   if (istr.good())
   {
      c = istr.get();
      if (c != -1) { outString += (char) c; }
   }

   int e = -1;
   if (error_istr.good())
   {
      e = error_istr.get();
      if (e != -1) { errorString += (char)e; }
   }

   keepGoing = ((c != -1) || (e != -1));
}

francisr
Posts: 21
Joined: 09 Dec 2007, 13:19

Re: Poco Process correct usage?

Postby francisr » 22 Nov 2008, 21:11

Dang, I suspected it would be something stupid. Thanks!


Return to “Support”

Who is online

Users browsing this forum: No registered users and 1 guest

cron