Georg Baum wrote: > man 3 popen answers that: yes, found that in the meantime. thanks.
> 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? errno is ECHILD (no child processes), so your guess is probably right. OTOH man popen says: "If pclose() cannot obtain the child status, errno is set to ECHILD", which sounds a bit vague. Is the attached safe? It sets pret to 0 when errno is ECHILD and fixes the bug. It also prints out an error message both when popen does not succeed and when pclose gets an error (other than ECHILD). > BTW, what is the return value if you run "kpsewhich test.bib"? It should be > 0. It is 0. Everything seems to be o.k. regarding kpsewhich. Regards, Jürgen.
Index: src/support/filetools.C =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/support/filetools.C,v retrieving revision 1.180 diff -u -r1.180 filetools.C --- src/support/filetools.C 1 Apr 2004 21:03:52 -0000 1.180 +++ src/support/filetools.C 2 Apr 2004 17:31:21 -0000 @@ -1181,8 +1181,10 @@ FILE * inf = ::popen(cmd.c_str(), os::popen_read_mode()); // (Claus Hentschel) Check if popen was succesful ;-) - if (!inf) + if (!inf) { return make_pair(-1, string()); + lyxerr << "RunCommand:: could not start child process" << endl; + } string ret; int c = fgetc(inf); @@ -1190,7 +1192,13 @@ ret += static_cast<char>(c); c = fgetc(inf); } - int const pret = pclose(inf); + int pret = pclose(inf); + // reset return variable if child process has already terminated + // successfully before pclose was called. + if (errno == ECHILD) + pret = 0; + if (pret == -1) + perror("RunCommand:: could not terminate child process"); return make_pair(pret, ret); }