Handle multiple double-quoted strings using Win32's system() call.

Document limitations.
This commit is contained in:
Bruce Momjian 2004-06-10 16:35:18 +00:00
parent 93db6f6ae2
commit 10a3d19ad4
4 changed files with 32 additions and 17 deletions

View File

@ -39,7 +39,7 @@
* Portions Copyright (c) 1994, Regents of the University of California
* Portions taken from FreeBSD.
*
* $PostgreSQL: pgsql/src/bin/initdb/initdb.c,v 1.35 2004/06/03 00:07:36 momjian Exp $
* $PostgreSQL: pgsql/src/bin/initdb/initdb.c,v 1.36 2004/06/10 16:35:16 momjian Exp $
*
*-------------------------------------------------------------------------
*/
@ -812,12 +812,12 @@ test_connections(void)
for (i = 0; i < len; i++)
{
snprintf(cmd, sizeof(cmd),
"\"%s\" -boot -x0 %s "
"%s\"%s\" -boot -x0 %s "
"-c shared_buffers=%d -c max_connections=%d template1 "
"<%s >%s 2>&1",
backend_exec, boot_options,
"< \"%s\" > \"%s\" 2>&1%s",
SYSTEMQUOTE, backend_exec, boot_options,
conns[i] * 5, conns[i],
DEVNULL, DEVNULL);
DEVNULL, DEVNULL, SYSTEMQUOTE);
status = system(cmd);
if (status == 0)
break;
@ -848,12 +848,12 @@ test_buffers(void)
for (i = 0; i < len; i++)
{
snprintf(cmd, sizeof(cmd),
"\"%s\" -boot -x0 %s "
"%s\"%s\" -boot -x0 %s "
"-c shared_buffers=%d -c max_connections=%d template1 "
"<%s >%s 2>&1",
backend_exec, boot_options,
"< \"%s\" > \"%s\" 2>&1%s",
SYSTEMQUOTE, backend_exec, boot_options,
bufs[i], n_connections,
DEVNULL, DEVNULL);
DEVNULL, DEVNULL, SYSTEMQUOTE);
status = system(cmd);
if (status == 0)
break;

View File

@ -4,7 +4,7 @@
*
* Portions Copyright (c) 1996-2003, PostgreSQL Global Development Group
*
* $PostgreSQL: pgsql/src/bin/pg_ctl/pg_ctl.c,v 1.8 2004/06/09 17:36:07 momjian Exp $
* $PostgreSQL: pgsql/src/bin/pg_ctl/pg_ctl.c,v 1.9 2004/06/10 16:35:17 momjian Exp $
*
*-------------------------------------------------------------------------
*/
@ -224,11 +224,12 @@ start_postmaster(void)
/* Does '&' work on Win32? */
if (log_file != NULL)
snprintf(cmd, MAXPGPATH, "'%s' %s < %s >> '%s' 2>&1 &",
postgres_path, post_opts, DEVNULL, log_file);
snprintf(cmd, MAXPGPATH, "%s\"%s\" %s < %s >> \"%s\" 2>&1 &%s",
SYSTEMQUOTE, postgres_path, post_opts, DEVNULL, log_file,
SYSTEMQUOTE);
else
snprintf(cmd, MAXPGPATH, "'%s' %s < %s 2>&1 &",
postgres_path, post_opts, DEVNULL);
snprintf(cmd, MAXPGPATH, "%s\"%s\" %s < \"%s\" 2>&1 &%s",
SYSTEMQUOTE, postgres_path, post_opts, DEVNULL, SYSTEMQUOTE);
return system(cmd);
}

View File

@ -6,7 +6,7 @@
* Portions Copyright (c) 1994, Regents of the University of California
*
*
* $PostgreSQL: pgsql/src/bin/pg_dump/pg_dumpall.c,v 1.40 2004/06/09 17:37:28 momjian Exp $
* $PostgreSQL: pgsql/src/bin/pg_dump/pg_dumpall.c,v 1.41 2004/06/10 16:35:17 momjian Exp $
*
*-------------------------------------------------------------------------
*/
@ -690,7 +690,8 @@ runPgDump(const char *dbname)
const char *p;
int ret;
appendPQExpBuffer(cmd, "'%s' %s -Fp '", pg_dump_bin, pgdumpopts->data);
appendPQExpBuffer(cmd, "%s\"%s\" %s -Fp '", SYSTEMQUOTE, pg_dump_bin,
pgdumpopts->data);
/* Shell quoting is not quite like SQL quoting, so can't use fmtId */
for (p = dbname; *p; p++)
@ -702,6 +703,7 @@ runPgDump(const char *dbname)
}
appendPQExpBufferChar(cmd, '\'');
appendStringLiteral(cmd, SYSTEMQUOTE, false);
if (verbose)
fprintf(stderr, _("%s: running \"%s\"\n"), progname, cmd->data);

View File

@ -6,7 +6,7 @@
* Portions Copyright (c) 1996-2003, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
* $PostgreSQL: pgsql/src/include/port.h,v 1.40 2004/06/03 00:07:38 momjian Exp $
* $PostgreSQL: pgsql/src/include/port.h,v 1.41 2004/06/10 16:35:18 momjian Exp $
*
*-------------------------------------------------------------------------
*/
@ -72,6 +72,18 @@ extern int find_other_exec(const char *argv0, const char *target,
#define DEVNULL "/dev/null"
#endif
/*
* Win32 needs double quotes at the beginning and end of system()
* strings. If not, it gets confused with multiple quoted strings.
* It also must use double-quotes around the executable name
* and any files use for redirection. Other args can use single-quotes.
*/
#ifdef WIN32
#define SYSTEMQUOTE "\""
#else
#define SYSTEMQUOTE ""
#endif
/* Portable delay handling */
extern void pg_usleep(long microsec);