On Tue, Sep 01, 2026 at 08:35:31PM +0200, Pavel Sanda wrote:
> On Mon, Aug 31, 2026 at 09:54:20PM +0200, Pavel Sanda wrote:
> > The first batch of patches tries to sanitize runCommand() calls.
> 
> The next one uses new startscriptArgv to close kpsewhich hole
> in a less fragile way.

The fifth kicks runCommand from layout2layout and prefs2prefs.
Pavel
>From dde4eae9975828b52fe6f53ec5168be785471d50 Mon Sep 17 00:00:00 2001
From: Pavel Sanda <[email protected]>
Date: Thu, 28 May 2026 15:25:07 +0200
Subject: [PATCH 08/11] Route layout2layout and prefs2prefs through argv form

Retires runCommand() - DiD  only, strings not deliverable here from documents.

Tier 01 DiD / argv 03c: argv-form layout2layout + prefs2prefs;

Assisted-by: Claude Opus 5
---
 src/TextClass.cpp | 32 +++++++++++++++++++++-----------
 src/support/filetools.cpp | 25 ++++++++++++++++---------
 2 files changed, 37 insertions(+), 20 deletions(-)

diff --git a/src/TextClass.cpp b/src/TextClass.cpp
index bb7bf8d754..85d82d18bd 100644
--- a/src/TextClass.cpp
+++ b/src/TextClass.cpp
@@ -28,6 +28,7 @@
 #include "frontends/alert.h"
 
 #include "support/lassert.h"
+#include "support/convert.h"
 #include "support/debug.h"
 #include "support/FileName.h"
 #include "support/filetools.h"
@@ -35,6 +36,7 @@
 #include "support/Lexer.h"
 #include "support/lstrings.h"
 #include "support/os.h"
+#include "support/Systemcall.h"
 #include "support/TempFile.h"
 
 #include <algorithm>
@@ -80,17 +82,25 @@ bool layout2layout(FileName const & filename, FileName const & tempfile,
 		return false;
 	}
 
-	ostringstream command;
-	command << os::python() << ' ' << quoteName(script.toFilesystemEncoding())
-	        << " -t " << format
-	        << ' ' << quoteName(filename.toFilesystemEncoding())
-	        << ' ' << quoteName(tempfile.toFilesystemEncoding());
-	string const command_str = command.str();
-
-	LYXERR(Debug::TCLASS, "Running `" << command_str << '\'');
-
-	cmd_ret const ret = runCommand(command_str);
-	if (!ret.valid) {
+	vector<string> argv = os::pythonArgvForm();
+	if (argv.empty()) {
+		LYXERR0("No Python interpreter available for layout2layout.");
+		return false;
+	}
+	argv.push_back(script.toFilesystemEncoding());
+	argv.push_back("-t");
+	argv.push_back(convert<string>(format));
+	argv.push_back(filename.toFilesystemEncoding());
+	argv.push_back(tempfile.toFilesystemEncoding());
+
+	string const program = argv.front();
+	argv.erase(argv.begin());
+	LYXERR(Debug::TCLASS, "Running layout2layout via argv: " << program
+	       << " with " << argv.size() << " arguments");
+
+	Systemcall one;
+	int const ret = one.startscriptArgv(program, argv, nullptr);
+	if (ret != Systemcall::OK) {
 		if (format == LAYOUT_FORMAT)
 			LYXERR0("Conversion of layout with layout2layout.py has failed.");
 		return false;
diff --git a/src/support/filetools.cpp b/src/support/filetools.cpp
index 7e11a18290..00d2cfebad 100644
--- a/src/support/filetools.cpp
+++ b/src/support/filetools.cpp
@@ -1304,17 +1304,24 @@ bool prefs2prefs(FileName const & filename, FileName const & tempfile, bool lfun
 		return false;
 	}
 
-	ostringstream command;
-	command << os::python() << ' ' << quoteName(script.toFilesystemEncoding())
-	  << ' ' << (lfuns ? "-l" : "-p") << ' '
-		<< quoteName(filename.toFilesystemEncoding())
-		<< ' ' << quoteName(tempfile.toFilesystemEncoding());
-	string const command_str = command.str();
+	vector<string> argv = os::pythonArgvForm();
+	if (argv.empty()) {
+		LYXERR0("No Python interpreter available for prefs2prefs.");
+		return false;
+	}
+	argv.push_back(script.toFilesystemEncoding());
+	argv.push_back(lfuns ? "-l" : "-p");
+	argv.push_back(filename.toFilesystemEncoding());
+	argv.push_back(tempfile.toFilesystemEncoding());
 
-	LYXERR(Debug::FILES, "Running `" << command_str << '\'');
+	string const program = argv.front();
+	argv.erase(argv.begin());
+	LYXERR(Debug::FILES, "Running prefs2prefs via argv: " << program
+	       << " with " << argv.size() << " arguments");
 
-	cmd_ret const ret = runCommand(command_str);
-	if (!ret.valid) {
+	Systemcall one;
+	int const ret = one.startscriptArgv(program, argv, nullptr);
+	if (ret != Systemcall::OK) {
 		LYXERR0("Could not run file conversion script prefs2prefs.py.");
 		return false;
 	}
-- 
2.39.5

-- 
lyx-devel mailing list
[email protected]
https://lists.lyx.org/mailman/listinfo/lyx-devel

Reply via email to