Skip to content

Commit f885449

Browse files
committed
On Windows, use COMSPEC to find the location of cmd.exe.
Historically, psql consulted COMSPEC to spawn a shell in its \! command, but we just invoked "cmd" when spawning shells in pg_ctl and pg_regress. It seems better to rely on the environment variable, if it's set, in all cases. It's debatable whether this is a bug fix or just a behavioral change, so no back-patch. Juan José Santamaría Flecha Discussion: https://postgr.es/m/16080-5d7f03222469f717@postgresql.org
1 parent bd1ef57 commit f885449

File tree

2 files changed

+17
-5
lines changed

2 files changed

+17
-5
lines changed

src/bin/pg_ctl/pg_ctl.c

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -513,13 +513,19 @@ start_postmaster(void)
513513
* "exec", so we don't get to find out the postmaster's PID immediately.
514514
*/
515515
PROCESS_INFORMATION pi;
516+
const char *comspec;
517+
518+
/* Find CMD.EXE location using COMSPEC, if it's set */
519+
comspec = getenv("COMSPEC");
520+
if (comspec == NULL)
521+
comspec = "CMD";
516522

517523
if (log_file != NULL)
518-
snprintf(cmd, MAXPGPATH, "CMD /C \"\"%s\" %s%s < \"%s\" >> \"%s\" 2>&1\"",
519-
exec_path, pgdata_opt, post_opts, DEVNULL, log_file);
524+
snprintf(cmd, MAXPGPATH, "\"%s\" /C \"\"%s\" %s%s < \"%s\" >> \"%s\" 2>&1\"",
525+
comspec, exec_path, pgdata_opt, post_opts, DEVNULL, log_file);
520526
else
521-
snprintf(cmd, MAXPGPATH, "CMD /C \"\"%s\" %s%s < \"%s\" 2>&1\"",
522-
exec_path, pgdata_opt, post_opts, DEVNULL);
527+
snprintf(cmd, MAXPGPATH, "\"%s\" /C \"\"%s\" %s%s < \"%s\" 2>&1\"",
528+
comspec, exec_path, pgdata_opt, post_opts, DEVNULL);
523529

524530
if (!CreateRestrictedProcess(cmd, &pi, false))
525531
{

src/test/regress/pg_regress.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1193,9 +1193,15 @@ spawn_process(const char *cmdline)
11931193
PROCESS_INFORMATION pi;
11941194
char *cmdline2;
11951195
HANDLE restrictedToken;
1196+
const char *comspec;
1197+
1198+
/* Find CMD.EXE location using COMSPEC, if it's set */
1199+
comspec = getenv("COMSPEC");
1200+
if (comspec == NULL)
1201+
comspec = "CMD";
11961202

11971203
memset(&pi, 0, sizeof(pi));
1198-
cmdline2 = psprintf("cmd /c \"%s\"", cmdline);
1204+
cmdline2 = psprintf("\"%s\" /c \"%s\"", comspec, cmdline);
11991205

12001206
if ((restrictedToken =
12011207
CreateRestrictedProcess(cmdline2, &pi)) == 0)

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy