Before this will return the exit status you must have waited for the process to exit, using either pstreambuf::wait() or pstreambuf::close() (which calls wait())
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
But this seems to make file handles not to be closed: when running the above in loop I finally get the "Too many files open" error (from rdbuf()->error()).
Am I not using the class correctly, or is this a bug? In the code of exited() there's a TODO item about calling close_fd_array(), which seems to be related to the behaviour I'm experiencing.
Thanks for any help,
/Danny
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Thanks. I've been using the method from your previous post in the interim and it works.
I have downloaded the new release (the first one to so according to SF.net), but I will only integrate with it next week or so, as I have other problems right now.
/Danny
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Is there a way to get the exit status of a command
which was executed via the ipstream class?
E.g., I want to
ipstream command("ls some_file 2>&1");
while ( getline(ipstream ...) )
{
}
if ( ipstream.status() != 0 ??? )
{
cout << "command failed with error << ipstream.status() << endl;
}
else
{
cout << "command successfully completed" << endl;
}
There is a status member on the stream buffer class, see http://pstreams.sourceforge.net/doc/classredi_1_1basic__pstreambuf.html#a12
e.g.
if (iipstream.rdbuf()->status() != 0)
// ...
Before this will return the exit status you must have waited for the process to exit, using either pstreambuf::wait() or pstreambuf::close() (which calls wait())
I have been using the following:
ipstream command("/bin/ls -l");
if ( command.is_open() )
{
while (getline(command, str))
{
cout << str << endl;
}
if (true == command.rdbuf()->exited())
{
cout << "status="
<< command.rdbuf()->status() << endl;
}
else
{
cerr << "process not exited" << endl;
}
command.close();
}
But this seems to make file handles not to be closed: when running the above in loop I finally get the "Too many files open" error (from rdbuf()->error()).
Am I not using the class correctly, or is this a bug? In the code of exited() there's a TODO item about calling close_fd_array(), which seems to be related to the behaviour I'm experiencing.
Thanks for any help,
/Danny
Hi Danny,
Sorry for not replying - I managed to forget to respond.
There was a file descriptor leak which I fixed in June, but
didn't make a new release until the new 0.5.0 release I
made two days ago.
Using the latest version I can run your example code in a
loop with a resource limit of 6 open files, so nothing
seems to be leaking now.
Please let me know if you have any problems with the
new release.
thanks
jon
Hi Jon,
Thanks. I've been using the method from your previous post in the interim and it works.
I have downloaded the new release (the first one to so according to SF.net), but I will only integrate with it next week or so, as I have other problems right now.
/Danny