From 4686d184967c0c747777c8edcc6b00dc023b8aa9 Mon Sep 17 00:00:00 2001 From: Robin Haberkorn Date: Sat, 5 Jun 2021 23:42:03 +0200 Subject: Windows: normalize $COMSPEC * Environment variables are case insensitive on Windows while SciTECO variables are case sensitive. We must therefore make sure that we first unset any $COMSPEC or $ComSpec from the environment before resetting it, thereby fixing its case. * Fixes command execution via on systems where the variable was not called $ComSpec. --- src/main.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'src/main.c') diff --git a/src/main.c b/src/main.c index 3d149d4..38b1197 100644 --- a/src/main.c +++ b/src/main.c @@ -245,7 +245,16 @@ teco_initialize_environment(const gchar *program) g_free(abs_path); #ifdef G_OS_WIN32 - g_setenv("ComSpec", "cmd.exe", FALSE); + /* + * NOTE: Environment variables are case-insensitive on Windows + * and there may be either a $COMSPEC or $ComSpec variable. + * By unsetting and resetting $COMSPEC, we make sure that + * it exists with defined case in the environment and therefore + * as a Q-Register. + */ + g_autofree gchar *comspec = g_strdup(g_getenv("COMSPEC") ? : "cmd.exe"); + g_unsetenv("COMSPEC"); + g_setenv("COMSPEC", comspec, TRUE); #elif defined(G_OS_UNIX) g_setenv("SHELL", "/bin/sh", FALSE); #endif -- cgit v1.2.3