44 *
55 * Portions Copyright (c) 1996-2003, PostgreSQL Global Development Group
66 *
7- * $PostgreSQL: pgsql/src/bin/pg_ctl/pg_ctl.c,v 1.13 2004/06/10 22:20:53 momjian Exp $
7+ * $PostgreSQL: pgsql/src/bin/pg_ctl/pg_ctl.c,v 1.14 2004/06/11 00:57:25 momjian Exp $
88 *
99 *-------------------------------------------------------------------------
1010 */
@@ -221,6 +221,41 @@ start_postmaster(void)
221221 * to pass everything to a shell to process them.
222222 */
223223char cmd [MAXPGPATH ];
224+ int ret ;
225+ char * pgexec = postgres_path ;
226+
227+ #ifdef WIN32
228+ /*
229+ *Win32 has a problem with the interaction between START and system().
230+ *There is no way to quote the executable name passed to START.
231+ *Therefore, we put the executable name in a temporary batch file
232+ *and run it via START.
233+ */
234+ char tmp [MAXPGPATH ]= "C:\\PG_CTL_XXXXXX" ,/* good location? */
235+ bat [MAXPGPATH ];
236+ int fd = mkstemp (tmp );
237+
238+ if (fd == -1 )
239+ {
240+ fprintf (stderr ,_ ("%s: cannot create batch file %s to start server: %s\n" ),
241+ progname ,tmp ,strerror (errno ));
242+ exit (1 );
243+ }
244+ write (fd ,postgres_path ,strlen (postgres_path ));
245+ write (fd ,"\n" ,1 );
246+ close (fd );
247+
248+ strcpy (bat ,tmp );
249+ strcat (bat ,".BAT" );
250+ pgexec = bat ;
251+ if (rename (tmp ,bat )== -1 )
252+ {
253+ fprintf (stderr ,_ ("%s: cannot rename batch file %s to %s: %s\n" ),
254+ progname ,tmp ,bat ,strerror (errno ));
255+ unlink (tmp );
256+ exit (1 );
257+ }
258+ #endif
224259
225260if (log_file != NULL )
226261/* Win32 needs START /B rather than "&" */
@@ -229,16 +264,28 @@ start_postmaster(void)
229264#else
230265snprintf (cmd ,MAXPGPATH ,"%sSTART /B \"%s\" %s < \"%s\" >> \"%s\" 2>&1%s" ,
231266#endif
232- SYSTEMQUOTE ,postgres_path ,post_opts ,DEVNULL ,log_file ,
267+ SYSTEMQUOTE ,pgexec ,post_opts ,DEVNULL ,log_file ,
233268SYSTEMQUOTE );
234269else
235270#ifndef WIN32
236271snprintf (cmd ,MAXPGPATH ,"%s\"%s\" %s < \"%s\" 2>&1 &%s" ,
237272#else
238273snprintf (cmd ,MAXPGPATH ,"%sSTART /B \"%s\" %s < \"%s\" 2>&1%s" ,
239274#endif
240- SYSTEMQUOTE ,postgres_path ,post_opts ,DEVNULL ,SYSTEMQUOTE );
241- return system (cmd );
275+ SYSTEMQUOTE ,pgexec ,post_opts ,DEVNULL ,SYSTEMQUOTE );
276+
277+ ret = system (cmd );
278+
279+ #ifdef WIN32
280+ /* We are unlinking it while it is running, but that should be OK */
281+ if (unlink (bat ))
282+ {
283+ fprintf (stderr ,_ ("%s: cannot remove batch file %s: %s\n" ),
284+ progname ,bat ,strerror (errno ));
285+ exit (1 );
286+ }
287+ #endif
288+ return ret ;
242289}
243290
244291