diff --git a/src/bin/pg_ctl/pg_ctl.c b/src/bin/pg_ctl/pg_ctl.c index a3fd002..a2005c1 100644 --- a/src/bin/pg_ctl/pg_ctl.c +++ b/src/bin/pg_ctl/pg_ctl.c @@ -513,13 +513,20 @@ start_postmaster(void) * "exec", so we don't get to find out the postmaster's PID immediately. */ PROCESS_INFORMATION pi; + char *comspec; + const char *cmd_exec = "CMD"; + + /* CMD location using COMSPEC */ + comspec = getenv("COMSPEC"); + if (comspec == NULL) + comspec = cmd_exec; if (log_file != NULL) - snprintf(cmd, MAXPGPATH, "CMD /C \"\"%s\" %s%s < \"%s\" >> \"%s\" 2>&1\"", - exec_path, pgdata_opt, post_opts, DEVNULL, log_file); + snprintf(cmd, MAXPGPATH, "\"%s\" /C \"\"%s\" %s%s < \"%s\" >> \"%s\" 2>&1\"", + comspec, exec_path, pgdata_opt, post_opts, DEVNULL, log_file); else - snprintf(cmd, MAXPGPATH, "CMD /C \"\"%s\" %s%s < \"%s\" 2>&1\"", - exec_path, pgdata_opt, post_opts, DEVNULL); + snprintf(cmd, MAXPGPATH, "\"%s\" /C \"\"%s\" %s%s < \"%s\" 2>&1\"", + comspec, exec_path, pgdata_opt, post_opts, DEVNULL); if (!CreateRestrictedProcess(cmd, &pi, false)) { diff --git a/src/test/regress/pg_regress.c b/src/test/regress/pg_regress.c index 6554ce2..44797a2 100644 --- a/src/test/regress/pg_regress.c +++ b/src/test/regress/pg_regress.c @@ -1193,9 +1193,16 @@ spawn_process(const char *cmdline) PROCESS_INFORMATION pi; char *cmdline2; HANDLE restrictedToken; + char *comspec; + const char *cmd_exec = "CMD"; + + /* CMD location using COMSPEC */ + comspec = getenv("COMSPEC"); + if (comspec == NULL) + comspec = cmd_exec; memset(&pi, 0, sizeof(pi)); - cmdline2 = psprintf("cmd /c \"%s\"", cmdline); + cmdline2 = psprintf("\"%s\" /c \"%s\"", comspec, cmdline); if ((restrictedToken = CreateRestrictedProcess(cmdline2, &pi)) == 0)