On Sun, Sep 13, 2026 at 07:05:33PM +0200, Pavel Sanda wrote: > Ok, with 03 class finished (invocation on load) I'll continue with > misc lefotvers (04 class). > > First - guard better esoteric biblio paperviewer from context menu.
Last but one. Kicking runCommand() from CAS handling. To be clear, the current form is safe and if I was not pushing shell based runCommand() out of source code, it could stay as it is. The rewrite is not mechanical and it would be great if anyone on Windows could test that e.g. maxima still delivers results in mathed. On linux it works (tested octave and maxima). Pavel
>From 6539232ea9d20f8c9253d0887c23f6fb813c1b60 Mon Sep 17 00:00:00 2001 From: Pavel Sanda <[email protected]> Date: Thu, 17 Sep 2026 02:55:40 +0200 Subject: [PATCH 12/14] Run the CAS through Systemcall instead of runCommand Rerouting to argv form would not work here (unless we rewrite the API just for this consumer so it deals with stdin/out). Fortunately we have startscript() which spawns without a shell and its parsecmd() already understands the redirections these commands use, including the 2>&1 that octave is invoked with. startscript() reports an exit code rather than the output, so collect the output in a second temp file and read it back. Compatibility change here, runCommand() used to return the raw bytes, while fileContents() decodes them as UTF-8 and to_utf8() encodes them back: output which is not valid UTF-8 now comes back with replacement characters, and output containing a NUL byte is truncated there. Should not be a problem for CAS exchange though. Tier 01 DiD / argv 04c: CAS via Systemcall, no shell Assisted-by: Claude Opus 5 --- src/mathed/MathExtern.cpp | 33 +++++++++++++++++++++++++++++---- 1 file changed, 29 insertions(+), 4 deletions(-) diff --git a/src/mathed/MathExtern.cpp b/src/mathed/MathExtern.cpp index 531138b358..629d3f1ee6 100644 --- a/src/mathed/MathExtern.cpp +++ b/src/mathed/MathExtern.cpp @@ -43,6 +43,7 @@ #include "support/filetools.h" #include "support/gettext.h" #include "support/lstrings.h" +#include "support/Systemcall.h" #include "support/TempFile.h" #include "support/textutils.h" @@ -1136,13 +1137,37 @@ namespace { ofstream os(cas_tmpfile.toFilesystemEncoding().c_str()); os << data << endl; os.close(); - string command = cmd + " < " - + quoteName(cas_tmpfile.toFilesystemEncoding()); + + // startscript() reports an exit code, so collect the output of + // the CAS in a file as well. + unique_ptr<TempFile> outfile(new TempFile("casoutput")); + outfile->setAutoRemove(false); + FileName const cas_outfile = outfile->name(); + outfile.reset(); + + if (cas_outfile.empty()) { + lyxerr << "Warning: cannot create temporary file." + << endl; + cas_tmpfile.removeFile(); + return string(); + } + + string const command = cmd + + " < " + quoteName(cas_tmpfile.toFilesystemEncoding()) + + " > " + quoteName(cas_outfile.toFilesystemEncoding()); lyxerr << "calling: " << cmd << "\ninput: '" << data << "'" << endl; - cmd_ret const ret = runCommand(command); + Systemcall one; + one.startscript(Systemcall::Wait, command); + + // Read what the CAS produced whatever its exit code was: a + // failing run still prints the diagnostics the callers parse + // (octave is invoked with 2>&1 for exactly that reason). + string const result = to_utf8(cas_outfile.fileContents("UTF-8")); + cas_tmpfile.removeFile(); - return ret.result; + cas_outfile.removeFile(); + return result; } size_t get_matching_brace(string const & str, size_t i) -- 2.39.5
-- lyx-devel mailing list [email protected] https://lists.lyx.org/mailman/listinfo/lyx-devel
