pstreams-users Mailing List for PStreams
Brought to you by:
redi
You can subscribe to this list here.
2003 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
(1) |
Dec
|
---|---|---|---|---|---|---|---|---|---|---|---|---|
2004 |
Jan
|
Feb
|
Mar
|
Apr
|
May
(1) |
Jun
|
Jul
|
Aug
|
Sep
|
Oct
(2) |
Nov
|
Dec
|
2005 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
(2) |
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
2009 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
(4) |
Oct
(2) |
Nov
|
Dec
|
2010 |
Jan
|
Feb
|
Mar
(4) |
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
2012 |
Jan
|
Feb
|
Mar
|
Apr
(1) |
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
2013 |
Jan
|
Feb
(5) |
Mar
(1) |
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
From: Jonathan W. <pst...@ka...> - 2013-03-29 16:27:33
|
Hi Pstreams users, I want to make some changes to the Git history and push a rebased tree to the SourceForge repository, which is usually a very bad idea because it will cause a problem for anyone who has cloned the repository, because the upstream history will not match your local history. Is anyone using the repo, and if you are do you mind having to clone it again? If you have local changes in your copy of the master branch I can help you preserve them if needed. |
From: Johannes W. <jw...@te...> - 2013-02-06 14:40:41
|
On 02/06/2013 03:27 PM, Jonathan Wakely wrote: > On 6 February 2013 13:39, Johannes Wienke wrote: >> >> Actually the process I am inspecting is still alive, but there seems to >> be a bug in pstree when a thread of that process goes away. In that case >> pstree tries to access the thread's stat-file and exists with "No such >> file or directory" on stderr. Not exactly what I expected from such a >> tool... I will search for a different way to find all subprocesses. > > Eurgh, that's not very helpful either. > > I suppose you could read from the child process' stderr and if you get > that error then you could try calling pstree again, e.g. (untested) > > #include <pstreams/pstream.h> > #include <sstream> > #include <iostream> > > int main(int argc, char** argv) > { > std::string pid = argc > 1 ? argv[1] : "1"; > std::string pstreeOut; > while (pstreeOut.empty()) > { > redi::ipstream in("pstree -pa " + pid); > std::stringstream ss; > ss << in.rdbuf(); > pstreeOut = ss.str(); > > if (pstreeOut.empty()) { > ss << in.err().rdbuf(); > pstreeOut = ss.str(); > // handle pstree error when a thread terminates while processing > if (pstreeOut.find("No such file or directory") == > std::string::npos) > throw std::runtime_error("No such process: " + pid); > } > } > std::cout << pstreeOut << '\n'; > } > Hm, would be kind of an ugly workaround for a pstree bug, which I just don't want to know about. ;) In the mean time I just switched to using ps --no-headers -eo ppid,pid and implementing the recursion to find all subprocesses manually in C++. Thanks for your help Johannes |
From: Jonathan W. <pst...@ka...> - 2013-02-06 14:27:32
|
On 6 February 2013 13:39, Johannes Wienke wrote: > > Actually the process I am inspecting is still alive, but there seems to > be a bug in pstree when a thread of that process goes away. In that case > pstree tries to access the thread's stat-file and exists with "No such > file or directory" on stderr. Not exactly what I expected from such a > tool... I will search for a different way to find all subprocesses. Eurgh, that's not very helpful either. I suppose you could read from the child process' stderr and if you get that error then you could try calling pstree again, e.g. (untested) #include <pstreams/pstream.h> #include <sstream> #include <iostream> int main(int argc, char** argv) { std::string pid = argc > 1 ? argv[1] : "1"; std::string pstreeOut; while (pstreeOut.empty()) { redi::ipstream in("pstree -pa " + pid); std::stringstream ss; ss << in.rdbuf(); pstreeOut = ss.str(); if (pstreeOut.empty()) { ss << in.err().rdbuf(); pstreeOut = ss.str(); // handle pstree error when a thread terminates while processing if (pstreeOut.find("No such file or directory") == std::string::npos) throw std::runtime_error("No such process: " + pid); } } std::cout << pstreeOut << '\n'; } |
From: Johannes W. <jw...@te...> - 2013-02-06 13:39:37
|
Hi, Thanks for the quick reply! On 02/06/2013 02:19 PM, Jonathan Wakely wrote: > The expression 'ss << in.rdbuf()' will read from the pstreambuf until > End-Of-File is reached, which will only happen when the child process > closes its end of the pipe, which in your program will happen after > 'pstree' exits. So it should always wait for 'pstree' to finish, as > demonstrated by this program which takes 5 seconds to print the > output, because it has to wait for the child to finish sleeping and > exit: > > #include <pstreams/pstream.h> > #include <sstream> > #include <iostream> > > int main(int argc, char** argv) > { > std::string pid = argc > 1 ? argv[1] : "1"; > redi::ipstream in("pstree -pa " + pid + " && sleep 5"); > std::stringstream ss; > ss << in.rdbuf(); > std::string pstreeOut = ss.str(); > > if (pstreeOut.empty()) { > throw std::runtime_error("No such process: " + pid); > } > std::cout << pstreeOut << '\n'; > } > > My guess would be that the process you are trying to inspect has > exited and so pstree produces no output. On my GNU/Linux system > 'pstree' doesn't print an error or exit with non-zero status for a > non-existent PID, which isn't very helpful. If the processes you are > trying to view are owned by you then you could use this command: > > boost::format("kill -s 0 %d 2>&1 && pstree -pa %d") % pid % pid > > The kill command will not send a signal, but will print an error and > exit with a non-zero status if the process doesn't exist. Actually the process I am inspecting is still alive, but there seems to be a bug in pstree when a thread of that process goes away. In that case pstree tries to access the thread's stat-file and exists with "No such file or directory" on stderr. Not exactly what I expected from such a tool... I will search for a different way to find all subprocesses. Thanks, Johannes |
From: Jonathan W. <pst...@ka...> - 2013-02-06 13:19:32
|
On 6 February 2013 11:04, Johannes Wienke wrote: > Hi, > > I am trying to use pstreams to get the output from a system call to the > Unix pstree command. On stackoverflow I found the following post: > http://stackoverflow.com/questions/5309020/how-to-get-the-full-stream-output-with-pstreams/5309174 > > So what I am currently using is this code to read the output: > > redi::ipstream in(boost::str(boost::format("pstree -pa %d") % pid)); > std::stringstream ss; > ss << in.rdbuf(); > std::string pstreeOut = ss.str(); > > if (pstreeOut.empty()) { > throw NoSuchProcessException(pid); > } > > Most of the time this works, but sometimes the exception is triggered. I > had the suspicion that this code actually doesn't wait for pstree to > finish. Is anything wrong with the way I us pstrees? Hi, The expression 'ss << in.rdbuf()' will read from the pstreambuf until End-Of-File is reached, which will only happen when the child process closes its end of the pipe, which in your program will happen after 'pstree' exits. So it should always wait for 'pstree' to finish, as demonstrated by this program which takes 5 seconds to print the output, because it has to wait for the child to finish sleeping and exit: #include <pstreams/pstream.h> #include <sstream> #include <iostream> int main(int argc, char** argv) { std::string pid = argc > 1 ? argv[1] : "1"; redi::ipstream in("pstree -pa " + pid + " && sleep 5"); std::stringstream ss; ss << in.rdbuf(); std::string pstreeOut = ss.str(); if (pstreeOut.empty()) { throw std::runtime_error("No such process: " + pid); } std::cout << pstreeOut << '\n'; } My guess would be that the process you are trying to inspect has exited and so pstree produces no output. On my GNU/Linux system 'pstree' doesn't print an error or exit with non-zero status for a non-existent PID, which isn't very helpful. If the processes you are trying to view are owned by you then you could use this command: boost::format("kill -s 0 %d 2>&1 && pstree -pa %d") % pid % pid The kill command will not send a signal, but will print an error and exit with a non-zero status if the process doesn't exist. |
From: Johannes W. <jw...@te...> - 2013-02-06 11:23:59
|
Hi, I am trying to use pstreams to get the output from a system call to the Unix pstree command. On stackoverflow I found the following post: http://stackoverflow.com/questions/5309020/how-to-get-the-full-stream-output-with-pstreams/5309174 So what I am currently using is this code to read the output: redi::ipstream in(boost::str(boost::format("pstree -pa %d") % pid)); std::stringstream ss; ss << in.rdbuf(); std::string pstreeOut = ss.str(); if (pstreeOut.empty()) { throw NoSuchProcessException(pid); } Most of the time this works, but sometimes the exception is triggered. I had the suspicion that this code actually doesn't wait for pstree to finish. Is anything wrong with the way I us pstrees? Cheers, Johannes |
From: Jonathan W. <pst...@ka...> - 2012-04-13 21:42:02
|
I've imported the Pstreams CVS repository into Git. The project will still be hosted at SourceForge, but future changes will only be committed to the Git repo. See https://sourceforge.net/scm/?type=git&group_id=48695 for how to check it out. |
From: Jonathan W. <pst...@ka...> - 2010-03-20 12:03:15
|
On 20 March 2010 07:51, Carsten Rütz wrote: > Hi Jonathan, > > Thanks a lot for your reply. Now it does indeed work like expected! > > Just for your information: I noticed where it went wrong for me. > I read the following on http://pstreams.sourceforge.net/doc/ > > [quote] > [...] > redi::ipstream in("rm", argv, redi::pstreambuf::pstderr); ... > [/quote] > > > As I did not use an rpstream but an ipstream, I did not have a second > look at this and thus did not use in.err(). Hmm, you're right, the example is wrong! The reason is that for an ipstream, pstdout is always used: basic_ipstream(const std::string& command, pmode mode = pstdout) : istream_type(NULL), pbase_type(command, mode|pstdout) Notice how the mode is OR'd with pstdout. This is consistent with std::ifstream, which ensures you cannot open an ifstream that is not readable. For pstreams this is not the right thing to do, since the stream is still readable if mode == psdterr. I think I will fix the code so that the example (and your code) works. I will do something like: pmode make_readable(pmode mode) { if (!(mode & (pstdout|pstderr)) mode |= pstdout; return mode; } Thanks for noticing the problem, Jonathan |
From: Carsten R. <car...@gm...> - 2010-03-20 07:51:11
|
Hi Jonathan, Thanks a lot for your reply. Now it does indeed work like expected! Just for your information: I noticed where it went wrong for me. I read the following on http://pstreams.sourceforge.net/doc/ [quote] [...] redi::ipstream in("rm", argv, redi::pstreambuf::pstderr); std::string errmsg; while (std::getline(in, errmsg)) { errors.push_back(errmsg); } [...] If an rpstream was used in the example above it would be necessary to replace the while condition like so: while (std::getline(in.err(), errmsg)) { errors.push_back(errmsg); } This form can also be used with the unrestricted pstream and ipstream classes, but it is not strictly necessary. [/quote] As I did not use an rpstream but an ipstream, I did not have a second look at this and thus did not use in.err(). Thanks for your help and your very nice pstreams! Regards, Carsten |
From: Jonathan W. <pst...@ka...> - 2010-03-19 22:24:44
|
On 16 March 2010 19:08, Carsten Rütz wrote: > Hello, > > I've got a problem when executing a command that writes an error message > to stderr. I simply cannot read the output on stderr: > > int main() { > redi::ipstream in("ls -T -l", redi::pstreambuf::pstderr); > > string line; > cout << "the error lines: " << endl; > if(in.is_open()) { > while(getline(in, line)) Hi, sorry for taking so long to reply. you need to call in.err() so that the stderr stream is active. Otherwise you are reading the stdout output. Regards, Jonathan |
From: Carsten R. <car...@gm...> - 2010-03-16 19:08:37
|
Hello, I've got a problem when executing a command that writes an error message to stderr. I simply cannot read the output on stderr: int main() { redi::ipstream in("ls -T -l", redi::pstreambuf::pstderr); string line; cout << "the error lines: " << endl; if(in.is_open()) { while(getline(in, line)) cout << "error line: " << line << endl; } cout << "end of error lines" << endl; in.close(); cout << "exited? " << in.rdbuf()->exited() << endl; cout << "status: " << in.rdbuf()->status() << endl; } the output of this program is: the error lines: end of error lines exited? 1 status: 512 so, the status is not okay (not 0), but I don't get the error that I would get when executing the command on the command line myself: $ ls -T -l ls: invalid tab size: -l btw: I tried to read from stdout as well to make sure that nothing is output there. But that only leaves me with an empty output as well and a race condition: $ ./test2 the error lines: ls: invalid tab size: -l end of error lines exited? 1 status: 512 $ ./test2 ls: invalid tab size: -l the error lines: end of error lines exited? 1 status: 512 All help on this is much appreciated! Carsten Rütz |
From: Jonathan W. <pst...@ka...> - 2009-10-07 09:37:04
|
2009/10/6 Mauro Baluda: > I'm using your beautiful library for a project but I don't get the > performances I expect > in particular 40% of the time is passed in xsputn! Hi, that doesn't sound good. > I suppose increasing the buffer size would alleviate the problem, is > it possible? The constant pstreams::bufsz determines the size of the streambuf buffer enum { bufsz = 32 }; ///< Size of pstreambuf buffers. You could try changing that and experimenting to see if it helps. Please let me know the results, I would be interested. The current value was chosen to be reasonably small so that output of shell commands would be available sooner, i.e. it was done to reduce latency when reading input, not to increase throughput. It is certainly not tuned for best performance. Do you have a simple testcase demonstrating the performance problem? I will take a look if you can provide an example, but don't have time right now to build and test something to investigate it. Jonathan |
From: Mauro B. <ma...@bg...> - 2009-10-06 19:42:22
|
I'm using your beautiful library for a project but I don't get the performances I expect in particular 40% of the time is passed in xsputn! I suppose increasing the buffer size would alleviate the problem, is it possible? Mauro -- Computer science is no more about computers than astronomy is about telescopes - Edsger W. Dijkstra |
From: Jonathan W. <pst...@ka...> - 2009-09-14 09:18:17
|
2009/9/14 Jonathan Wakely: > 2009/9/14 Pavel Alexeev (aka Pahan-Hubbitus): >> while (!child.eof() && (n = child.err().readsome(buf, sizeof(buf))) > >> 0){ Oops, these lines were missing from the quoted text in my last mail: >> std::cerr.write(buf, n).flush(); >> } >> return 0; >> } What I wrote still applies: the loop will exit if readsome returns zero, which is expected. Jonathan |
From: Jonathan W. <pst...@ka...> - 2009-09-14 09:15:10
|
2009/9/14 Pavel Alexeev (aka Pahan-Hubbitus): > > Perl there is not have any matter. Ok, I wrote another small example, now > instead of perl sh used. I add stream flushing and even exit of execution > process - still it is not work: > > int main(int argc,char *argv[]){ > > using namespace redi; > > const pstream::pmode mode = pstream::pstdin | pstream::pstdout | > pstream::pstderr; > char buf[1024]; > std::streamsize n; > > std::string testCmd0 = "date ; exit"; > child << testCmd0 << std::endl << std::flush; // endl should be enough, > flush for insurance > > while (!child.eof() && (n = child.err().readsome(buf, sizeof(buf))) > > 0){ > return 0; > } > > No errors there, but nothing read also! > OK, I had another look at what you're trying to do. 1) If you run simply 'sh' then it will not be an interactive shell because stdin is not connected to a terminal. So you need to run 'sh -i' to get an interactive shell (there might be a similar option needed to make perl run interactively.) 2) Your loop will exit if there is nothing to read. That is very likely to happen, because the child process takes some time to start, so there is a race condition. If the parent checks for output before the child has executed the commands then it will see nothing and the parent will exit. Look at how I wrote the example on the pstreams web page: the call to readsome() is in a nested loop, so that if it returns zero the outer loop will try again if we haven't reached eof. You cannot assume the child will produce output immediately. If you also add the '-x' option you can see what the shell is doing. For the purposes of debugging, it also helps to not connect to the child process' stderr, so that any errors are printed on your terminal. That means you will see the errors and it doesn't matter if your program is not correctly reading from stderr (so you would see the errors even with your buggy loop that doesn't wait for output.) This works for me: #include <iostream> #include <pstreams/pstream.h> int main(int argc, const char **argv) { using namespace redi; const pstream::pmode mode = pstream::pstdin | pstream::pstdout; char buf[1024]; std::streamsize n; pstream child("bash --norc -ix", mode); child << "date ; exit" << std::endl; while (!child.eof()) while ((n = child.readsome(buf, sizeof(buf))) > 0) std::cout.write(buf, n).flush(); return 0; } This prints: bash-4.0$ date ; exit + date + exit exit Mon Sep 14 10:04:40 BST 2009 This shows that pstreams will work with interactive processes, but you need to understand what the child process is doing and you need to be careful how you use the iostreams API to check for output and eof. Jonathan |
From: Jonathan W. <pst...@ka...> - 2009-09-13 20:25:48
|
2009/9/13 Pavel Alexeev (aka Pahan-Hubbitus): > Hello. > > I'm search documentation and examples, and nothing found... > Can I send stdin to process in similar way as I read it stdout? Yes, you can. > So, I search way to interract with process (in example below perl) > through write to its stdin and read answer from its stdout. Please, can > you provide small example how I can do it? Did you read the FAQ? http://pstreams.sourceforge.net/faq.html#faq_in_avail is relevant a situation like this. You might need to flush the stream to ensure that the characters you have written to it become available tothe child process. I'm not sure how easy it will be to use an interactive process, as it might be affected by buffering done internally by perl. Jonathan |
From: Pavel A. (a. Pahan-Hubbitus) <fo...@hu...> - 2009-09-13 15:19:52
|
Hello. I'm search documentation and examples, and nothing found... Can I send stdin to process in similar way as I read it stdout? I try modify you example from main page, but it is not reach hat I want: int main(int argc,char *argv[]){ using namespace redi; using namespace std; const pstream::pmode mode = pstream::pstdin | pstream::pstdout | pstream::pstderr; //pstream child("echo OUT1; sleep 1; echo ERR >&2; sleep 1; echo OUT2", mode); pstream child("perl", mode); char buf[1024]; std::streamsize n; bool finished[2] = { false, false }; //child << "print \"Hello world\";\n" << endl; child.write("print \"Hello world\";\n", 21); while (!finished[0] || !finished[1]){ if (!finished[0]){ while ((n = child.err().readsome(buf, sizeof(buf))) > 0){ std::cerr.write(buf, n).flush(); } if (child.eof()){ finished[0] = true; if (!finished[1]){ child.clear(); } } } if (!finished[1]){ while ((n = child.out().readsome(buf, sizeof(buf))) > 0){ std::cout.write(buf, n).flush(); } if (child.eof()){ finished[1] = true; if (!finished[0]){ child.clear(); } } } } return 0; } So, I search way to interract with process (in example below perl) through write to its stdin and read answer from its stdout. Please, can you provide small example how I can do it? With best wishes, Pavel Alexeev aka Pahan-Hubbitus. |
From: Jonathan W. <jw...@mi...> - 2005-07-05 11:24:07
|
Hi Romain, Sorry for the missing FAQ entry, I'll fix that tonight - the answer is probably sitting on my hard drive at home. There are two options for PStreams on Windows. The old popen-based branch works on Windows, using the _popen() and _pclose() calls - but these are only usable in console (not GUI) applications. There is also a full port of the PStreams code to Win32, which has been contributed and is being worked on by Francis Andre. That code involves a major re-write of the code and the changes conflict with some other changes I'm working on so that code is only in CVS, on a separate branch; it is not part of any release. I don't know the status of the branch, if Francis is reading this maybe he can supply more details. jon Romain Behar <rom...@ya...> on 05/07/2005 10:59:15 To: pst...@li... cc: (bcc: Jonathan Wakely/MINTEL/GB) Subject: [pstreams-users] PStream on Windows? Hello, I'm looking for a C++ library that runs processes and reads stdout and stderr output. It also has to run on the Win32 platform. I've found three libraries under a free license: * PStreams * libexecstream (http://libexecstream.sourceforge.net/) * TubeProcess (http://www.flyingpigs.dk/~cdbruun/software/ ) PStreams is the most active, but the FAQ says 'Can I use PStreams on Windows ?' in the menu and the section isn't in the page below! TubeProcess doesn't have as many features as the two other projects, so I'll choose between PStreams and libexecstream. Best regards, Romain ____________________________________________________ Yahoo! Sports Rekindle the Rivalries. Sign up for Fantasy Football http://football.fantasysports.yahoo.com ------------------------------------------------------- SF.Net email is sponsored by: Discover Easy Linux Migration Strategies from IBM. Find simple to follow Roadmaps, straightforward articles, informative Webcasts and more! Get everything you need to get up to speed, fast. http://ads.osdn.com/?ad_id=7477&alloc_id=16492&op=click _______________________________________________ PStreams-users mailing list PSt...@li... https://lists.sourceforge.net/lists/listinfo/pstreams-users |
From: Romain B. <rom...@ya...> - 2005-07-05 09:59:25
|
Hello, I'm looking for a C++ library that runs processes and reads stdout and stderr output. It also has to run on the Win32 platform. I've found three libraries under a free license: * PStreams * libexecstream (http://libexecstream.sourceforge.net/) * TubeProcess (http://www.flyingpigs.dk/~cdbruun/software/ ) PStreams is the most active, but the FAQ says 'Can I use PStreams on Windows ?' in the menu and the section isn't in the page below! TubeProcess doesn't have as many features as the two other projects, so I'll choose between PStreams and libexecstream. Best regards, Romain ____________________________________________________ Yahoo! Sports Rekindle the Rivalries. Sign up for Fantasy Football http://football.fantasysports.yahoo.com |
From: Jonathan W. <re...@ka...> - 2004-10-27 18:54:23
|
I have been contacted by Antonio S. de A. Terceiro, who is preparing a debian package for PStreams, and I am in the process of writing an RPM spec file. This means I can no longer avoid the sticky question of where to install the pstream.h file. Antonio and I have decided that the file should be installed in $PREFIX/include/pstreams/pstream.h (where $PREFIX is /usr/local/ or /usr). This means you should include it in your code like so: #include <pstreams/pstream.h> The rationale for this is that other packages could install a file called pstream.h which could clash with my header. To avoid this, PStreams installs to a sub-directory of include/ and should be included by specifying the sub-directory name. It is preferable to specify the sub-directory name in the #include directive, rather than specifying it on the command line with "-I". This is because it avoids an extra "-I" option just for pstream.h (assuming that $PREFIX is already in the set of include directories). Additionally, there will be a process.h header as part of PStreams at some point, which would be even more likely to clash with headers from other libraries if it wasn't in the pstreams sub-directory. Comments welcome, as ever, jon |
From: Jonathan W. <pst...@ka...> - 2004-10-17 17:44:29
|
I have just made a new release of PStreams, featuring numerous bug fixes and improvements. The release is version 0.5.0 (rather than 0.50) as I have switched to using major.minor.patchlevel numbering style. Release notes, ChangeLog and tar files are on SourceForge: http://sf.net/project/showfiles.php?group_id=48695&package_id=41869&release_id=275840 I've added a FAQ listing a few questions I've been asked, as well as some I expect to be asked at some point. I hope that will save people time, as I don't always reply to emails very quickly :-) Thank you to everyone who helped by reporting bugs, sending ideas or just letting me know they're using the code. jon |
From: <ben...@id...> - 2004-05-25 08:11:26
|
Dear Open Source developer I am doing a research project on "Fun and Software Development" in which I kindly invite you to participate. You will find the online survey under http://fasd.ethz.ch/qsf/. The questionnaire consists of 53 questions and you will need about 15 minutes to complete it. With the FASD project (Fun and Software Development) we want to define the motivational significance of fun when software developers decide to engage in Open Source projects. What is special about our research project is that a similar survey is planned with software developers in commercial firms. This procedure allows the immediate comparison between the involved individuals and the conditions of production of these two development models. Thus we hope to obtain substantial new insights to the phenomenon of Open Source Development. With many thanks for your participation, Benno Luthiger PS: The results of the survey will be published under http://www.isu.unizh.ch/fuehrung/blprojects/FASD/. We have set up the mailing list fa...@we... for this study. Please see http://fasd.ethz.ch/qsf/mailinglist_en.html for registration to this mailing list. _______________________________________________________________________ Benno Luthiger Swiss Federal Institute of Technology Zurich 8092 Zurich Mail: benno.luthiger(at)id.ethz.ch _______________________________________________________________________ |
From: Eric O. <e_p...@sb...> - 2003-11-18 12:53:18
|
I had an issue with pstream.h that showed up in Linux. I opened a pstream (in,out,stderr). While reading stdout, the read would eventually block because the stderr filled some buffer. I needed a way to check if a character is available on stdout (or stderr) - or a nice way to make the readline non-blocking. (if I have lots of stderr from the cmd) I added a function to the pstreambuff class. I don't know it this was the best way, but it worked /** * @return Report if characters available to be read */ template <typename C, typename T> inline bool basic_pstreambuf<C,T>::out_avail() { // setup select structures fd_set rfds; FD_ZERO(&rfds); // clear FD_SET(rpipe_[rsrc_out],&rfds); struct timeval tv; tv.tv_sec = 0; tv.tv_usec = 1; int maxfd = rpipe_[rsrc_out]; ::select(maxfd+1,&rfds,NULL,NULL,&tv); if (FD_ISSET(rpipe_[rsrc_out],&rfds)) { return(true); } else { return (false); } } ////////////////////////// Then I can just: redi::pstream parse(cmd,std::ios_base::in|std::ios_base::app); bool oav; while (getline(parse.out(),line)) { oav = parse.rdbuf()->out_avail(); process(line); while (!oav && (getline(parse.err(),line))) { process_error(line); oav = parse.rdbuf()->out_avail(); } } while ((getline(parse.err(),line))) { process_error(line); } parse.close(); /////////////////// very nice package BTW. Exactly what I needed - Eric Olson, eo...@ci... |