Thread: psql \! WIN32 cleanup

psql \! WIN32 cleanup

From
Bruce Momjian
Date:
The attached applied patch tests for COMSPEC in the right place and
supplies a reasonable shell default on Win32.

--
  Bruce Momjian                        |  http://candle.pha.pa.us
  pgman@candle.pha.pa.us               |  (610) 359-1001
  +  If your life is a hard drive,     |  13 Roberts Road
  +  Christ can be your backup.        |  Newtown Square, Pennsylvania 19073
Index: src/bin/psql/command.c
===================================================================
RCS file: /cvsroot/pgsql/src/bin/psql/command.c,v
retrieving revision 1.130
diff -c -c -r1.130 command.c
*** src/bin/psql/command.c    4 Nov 2004 22:25:14 -0000    1.130
--- src/bin/psql/command.c    6 Nov 2004 04:18:05 -0000
***************
*** 1525,1531 ****
--- 1525,1535 ----



+ #ifndef WIN32
  #define DEFAULT_SHELL "/bin/sh"
+ #else
+ #define DEFAULT_SHELL "c:/windows/system32/cmd.exe"
+ #endif

  static bool
  do_shell(const char *command)
***************
*** 1537,1547 ****
          char       *sys;
          const char *shellName = NULL;

  #ifdef WIN32
-         shellName = getenv("COMSPEC");
- #endif
          if (shellName == NULL)
!             shellName = getenv("SHELL");
          if (shellName == NULL)
              shellName = DEFAULT_SHELL;

--- 1541,1551 ----
          char       *sys;
          const char *shellName = NULL;

+         shellName = getenv("SHELL");
  #ifdef WIN32
          if (shellName == NULL)
!             shellName = getenv("COMSPEC");
! #endif
          if (shellName == NULL)
              shellName = DEFAULT_SHELL;


Re: psql \! WIN32 cleanup

From
Tom Lane
Date:
Bruce Momjian <pgman@candle.pha.pa.us> writes:
> The attached applied patch tests for COMSPEC in the right place and
> supplies a reasonable shell default on Win32.

> + #define DEFAULT_SHELL "c:/windows/system32/cmd.exe"

Is it really a good idea to assume that the Windows installation is on
drive C: ?

(This is an honest question, not a rhetorical one.  I dunno whether
inserting the C: is better than leaving it off.  I can think of cases
where either way will break, but I'm unsure what's most likely in
practice.)

            regards, tom lane

Re: psql \! WIN32 cleanup

From
Bruce Momjian
Date:
Tom Lane wrote:
> Bruce Momjian <pgman@candle.pha.pa.us> writes:
> > The attached applied patch tests for COMSPEC in the right place and
> > supplies a reasonable shell default on Win32.
>
> > + #define DEFAULT_SHELL "c:/windows/system32/cmd.exe"
>
> Is it really a good idea to assume that the Windows installation is on
> drive C: ?
>
> (This is an honest question, not a rhetorical one.  I dunno whether
> inserting the C: is better than leaving it off.  I can think of cases
> where either way will break, but I'm unsure what's most likely in
> practice.)

Not sure.  Should we just do "/windows/system32/cmd.exe" and leave off
the C:?  The previous default was "/bin/sh" and that certainly will not
work on Win32.

--
  Bruce Momjian                        |  http://candle.pha.pa.us
  pgman@candle.pha.pa.us               |  (610) 359-1001
  +  If your life is a hard drive,     |  13 Roberts Road
  +  Christ can be your backup.        |  Newtown Square, Pennsylvania 19073

Re: psql \! WIN32 cleanup

From
Gaetano Mendola
Date:
Bruce Momjian wrote:
> Tom Lane wrote:
>
>>Bruce Momjian <pgman@candle.pha.pa.us> writes:
>>
>>>The attached applied patch tests for COMSPEC in the right place and
>>>supplies a reasonable shell default on Win32.
>>
>>>+ #define DEFAULT_SHELL "c:/windows/system32/cmd.exe"
>>
>>Is it really a good idea to assume that the Windows installation is on
>>drive C: ?
>>
>>(This is an honest question, not a rhetorical one.  I dunno whether
>>inserting the C: is better than leaving it off.  I can think of cases
>>where either way will break, but I'm unsure what's most likely in
>>practice.)
>
>
> Not sure.  Should we just do "/windows/system32/cmd.exe" and leave off
> the C:?  The previous default was "/bin/sh" and that certainly will not
> work on Win32.

I think another path to try if COMSPEC is not defined is:

%SystemRoot%/system32/cmd.exe



Regards
Gaetano Mendola


Re: psql \! WIN32 cleanup

From
"Dave Page"
Date:


-----Original Message-----
From: pgsql-patches-owner@postgresql.org on behalf of Tom Lane
Sent: Sat 11/6/2004 5:30 AM
To: Bruce Momjian
Cc: PostgreSQL-patches
Subject: Re: [PATCHES] psql \! WIN32 cleanup

Bruce Momjian <pgman@candle.pha.pa.us> writes:
>> The attached applied patch tests for COMSPEC in the right place and
>> supplies a reasonable shell default on Win32.
>>
> + #define DEFAULT_SHELL "c:/windows/system32/cmd.exe"

> Is it really a good idea to assume that the Windows installation is on
> drive C: ?

I think it's worse to assume the installation directory is "windows". On windows 2000 for example, the default is
"winnt".
Probably the best default would simply be "cmd.exe" as it's invariably in the system path.

Regards, Dave


Re: psql \! WIN32 cleanup

From
Bruce Momjian
Date:
Dave Page wrote:
> Bruce Momjian <pgman@candle.pha.pa.us> writes:
> >> The attached applied patch tests for COMSPEC in the right place and
> >> supplies a reasonable shell default on Win32.
> >>
> > + #define DEFAULT_SHELL "c:/windows/system32/cmd.exe"
>
> > Is it really a good idea to assume that the Windows installation is on
> > drive C: ?
>
> I think it's worse to assume the installation directory is "windows". On windows 2000 for example, the default is
"winnt".
> Probably the best default would simply be "cmd.exe" as it's invariably in the system path.

Agreed.  Done.

--
  Bruce Momjian                        |  http://candle.pha.pa.us
  pgman@candle.pha.pa.us               |  (610) 359-1001
  +  If your life is a hard drive,     |  13 Roberts Road
  +  Christ can be your backup.        |  Newtown Square, Pennsylvania 19073