Juergen Spitzmueller wrote: > This means, for the file test.bib, "kpsewhich test.bib" is called. > Now when running lyx -dbg latex, we get: > kpse status = -1 > kpse result = `/usr/share/texmf/bibtex/bib/base/test.bib' > Bibfile: > > The question is now: why is kpsestatus=-1, which leeds to an empty return > string, even though kpse has found the correct path? > > Let's have a look at RunCommand: > cmd_ret const RunCommand(string const & cmd) > { > // One question is if we should use popen or > // create our own popen based on fork, exec, pipe > // of course the best would be to have a > // pstream (process stream), with the > // variants ipstream, opstream
You might want to check http://pstreams.sourceforge.net/ or http://members.aon.at/hstraub/linux/socket++/ (although the latter must be repaired by removing a "using namespace std;" from the headers before it can be used. I searched for a iostream based pipe wrapper last week, but was interrupted and have not really tried them yet. > FILE * inf = ::popen(cmd.c_str(), os::popen_read_mode()); > > // (Claus Hentschel) Check if popen was succesful ;-) > if (!inf) { > return make_pair(-1, string()); > lyxerr << "popen NOT successful!" << endl; > } > > string ret; > int c = fgetc(inf); > while (c != EOF) { > ret += static_cast<char>(c); > c = fgetc(inf); > } > int const pret = pclose(inf); > return make_pair(pret, ret); > } > > Note that I have inserted a print statement to check if popen was > succesful. Obviously this is the case, so pret must be -1. What does that > mean (and what the heck is popen and pclose)? man 3 popen answers that: popen creates a pipe to a child program, and pclose closes it. Doing this "by hand" with fork(), pipe() etc. is a pain if it should also work on windows (which uses a totally different mechanism). >From the man page: The pclose function returns -1 if wait4 returns an error, or some other error is detected. The wait4 manpage says: RETURN VALUE The process ID of the child which exited, -1 on error (in particular, when no unwaited-for child processes of the specified kind exist) or zero if WNOHANG was used and no child was available yet. In the latter two cases errno will be set appropriately. A wild guess: maybe pclose() returns -1 because the child did already terminate when pclose() was called? In this case the failure can of course be ignored. Maybe reading the errno variable could tell more? BTW, what is the return value if you run "kpsewhich test.bib"? It should be 0. Georg