public inbox for cygwin@cygwin.com
 help / color / mirror / Atom feed
* Proposal for new cygwin.bat which is independent from install directory
@ 2016-08-26 17:56 Christian Franke
  2016-08-26 19:38 ` Andrey Repin
  2016-08-30 15:43 ` Corinna Vinschen
  0 siblings, 2 replies; 18+ messages in thread
From: Christian Franke @ 2016-08-26 17:56 UTC (permalink / raw)
  To: cygwin

Traditionally setup.exe creates the /cygwin.bat file as follows if 
C:\cygwin is the install directory:
-----
@echo off

C:
chdir C:\cygwin\bin

bash --login -i
-----


The following should work since WinXP regardless of install directory:
-----
@echo off

cd /d %~dp0
if errorlevel 1 exit /b 1
cd bin
if errorlevel 1 exit /b 1

bash --login -i
-----

I would suggest to add something like the above as 
"/etc/defaults/cygwin.bat" to base-files package. The postinstall script 
should copy it to "/cygwin.bat" if new. The creation of this file could 
later be removed from setup.exe.

This more generic cygwin.bat is in particular useful for 'portable' 
installations of Cygwin on an USB device. I occasionally use such a 
installation to make rescue tools (dd, ddrescue, fdisk, hexedit, 
sleuthkit, ...) available to the minimal system provided by a Windows 
system repair CD.

Christian


--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: Proposal for new cygwin.bat which is independent from install directory
  2016-08-26 17:56 Proposal for new cygwin.bat which is independent from install directory Christian Franke
@ 2016-08-26 19:38 ` Andrey Repin
  2016-08-27 11:40   ` Bengt Larsson
  2016-08-27 13:23   ` Christian Franke
  2016-08-30 15:43 ` Corinna Vinschen
  1 sibling, 2 replies; 18+ messages in thread
From: Andrey Repin @ 2016-08-26 19:38 UTC (permalink / raw)
  To: Christian Franke, cygwin

Greetings, Christian Franke!

> Traditionally setup.exe creates the /cygwin.bat file as follows if 
> C:\cygwin is the install directory:
> -----
> @echo off

> C:
> chdir C:\cygwin\bin

> bash --login -i
> -----


> The following should work since WinXP regardless of install directory:
> -----
> @echo off

> cd /d %~dp0
> if errorlevel 1 exit /b 1
> cd bin
> if errorlevel 1 exit /b 1

> bash --login -i
> -----

Why so complicated?

@START "" /B "%~dp0bin\mintty.exe" -

Done.

> I would suggest to add something like the above as 
> "/etc/defaults/cygwin.bat" to base-files package. The postinstall script 
> should copy it to "/cygwin.bat" if new. The creation of this file could 
> later be removed from setup.exe.

> This more generic cygwin.bat is in particular useful for 'portable' 
> installations of Cygwin on an USB device. I occasionally use such a 
> installation to make rescue tools (dd, ddrescue, fdisk, hexedit, 
> sleuthkit, ...) available to the minimal system provided by a Windows 
> system repair CD.

Your variant is overengineered.


-- 
With best regards,
Andrey Repin
Friday, August 26, 2016 19:37:08

Sorry for my terrible english...


--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: Proposal for new cygwin.bat which is independent from install directory
  2016-08-26 19:38 ` Andrey Repin
@ 2016-08-27 11:40   ` Bengt Larsson
  2016-08-27 13:13     ` Christian Franke
  2016-08-27 13:23   ` Christian Franke
  1 sibling, 1 reply; 18+ messages in thread
From: Bengt Larsson @ 2016-08-27 11:40 UTC (permalink / raw)
  To: cygwin

Andrey Repin wrote:
>Greetings, Christian Franke!
>
>> Traditionally setup.exe creates the /cygwin.bat file as follows if 
>> C:\cygwin is the install directory:
>> -----
>> @echo off
>
>> C:
>> chdir C:\cygwin\bin
>
>> bash --login -i
>> -----
>
>
>> The following should work since WinXP regardless of install directory:
>> -----
>> @echo off
>
>> cd /d %~dp0
>> if errorlevel 1 exit /b 1
>> cd bin
>> if errorlevel 1 exit /b 1
>
>> bash --login -i
>> -----
>
>Why so complicated?

Also don't see why so complicated. While staying in the console, how
about:
-----
@echo off

cd /d "%~dp0\bin"

bash --login -i
-----

--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: Proposal for new cygwin.bat which is independent from install directory
  2016-08-27 11:40   ` Bengt Larsson
@ 2016-08-27 13:13     ` Christian Franke
  2016-08-27 16:20       ` Bengt Larsson
                         ` (2 more replies)
  0 siblings, 3 replies; 18+ messages in thread
From: Christian Franke @ 2016-08-27 13:13 UTC (permalink / raw)
  To: cygwin

Bengt Larsson wrote:
> Andrey Repin wrote:
>>> The following should work since WinXP regardless of install directory:
>>> -----
>>> @echo off
>>>
>>> cd /d %~dp0
>>> if errorlevel 1 exit /b 1
>>> cd bin
>>> if errorlevel 1 exit /b 1
>>>
>>> bash --login -i
>>> -----
>> Why so complicated? 
> Also don't see why so complicated. While staying in the console, how
> about:
> -----
> @echo off
>
> cd /d "%~dp0\bin"
>
> bash --login -i
> -----

An errorlevel check is IMO mandatory after a cd command. Otherwise 
another bash in the PATH might be started if the directory does not exist.
Hmm... therefore it is also better to change the last line to:

   .\bash --login -i

The directory change is intentionally done with two cd commands to avoid 
possible problems with cmd variants (on Win10 "%~dp0" expands to a path 
with trailing backslash).


Christian


--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: Proposal for new cygwin.bat which is independent from install directory
  2016-08-26 19:38 ` Andrey Repin
  2016-08-27 11:40   ` Bengt Larsson
@ 2016-08-27 13:23   ` Christian Franke
  2016-08-27 16:28     ` Andrey Repin
  1 sibling, 1 reply; 18+ messages in thread
From: Christian Franke @ 2016-08-27 13:23 UTC (permalink / raw)
  To: cygwin

Andrey Repin wrote:
> ...
> Why so complicated?
>
> @START "" /B "%~dp0bin\mintty.exe" -
>
> Done.

Possibly not. This does not run bash in current console. It starts a new 
mintty Window.


--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: Proposal for new cygwin.bat which is independent from install directory
  2016-08-27 13:13     ` Christian Franke
@ 2016-08-27 16:20       ` Bengt Larsson
  2016-08-27 16:20       ` Thomas Wolff
  2016-08-27 16:35       ` Andrey Repin
  2 siblings, 0 replies; 18+ messages in thread
From: Bengt Larsson @ 2016-08-27 16:20 UTC (permalink / raw)
  To: cygwin

Christian Franke wrote:
>Bengt Larsson wrote:
>> -----
>> @echo off
>>
>> cd /d "%~dp0\bin"
>>
>> bash --login -i
>> -----
>
>An errorlevel check is IMO mandatory after a cd command. Otherwise 
>another bash in the PATH might be started if the directory does not exist.
>Hmm... therefore it is also better to change the last line to:
>
>   .\bash --login -i
>
>The directory change is intentionally done with two cd commands to avoid 
>possible problems with cmd variants 

>(on Win10 "%~dp0" expands to a path 
>with trailing backslash).

You're right although "%~dp0\subdir" still works (tested on Win10). An
easier way to test exit status is

  cd somedir || exit /b 1

With info for those who may not know the syntax:
-----
@echo off

rem %~dp0 is directory of this batch file

cd /d "%~dp0\bin" || exit /b 1

.\bash --login -i
-----

--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: Proposal for new cygwin.bat which is independent from install directory
  2016-08-27 13:13     ` Christian Franke
  2016-08-27 16:20       ` Bengt Larsson
@ 2016-08-27 16:20       ` Thomas Wolff
  2016-08-27 16:35       ` Andrey Repin
  2 siblings, 0 replies; 18+ messages in thread
From: Thomas Wolff @ 2016-08-27 16:20 UTC (permalink / raw)
  To: cygwin

Am 27.08.2016 um 13:24 schrieb Christian Franke:
> Bengt Larsson wrote:
>> Andrey Repin wrote:
>>>> The following should work since WinXP regardless of install directory:
>>>> -----
>>>> @echo off
>>>>
>>>> cd /d %~dp0
>>>> if errorlevel 1 exit /b 1
>>>> cd bin
>>>> if errorlevel 1 exit /b 1
>>>>
>>>> bash --login -i
>>>> -----
>>> Why so complicated? 
>> Also don't see why so complicated. While staying in the console, how
>> about:
>> -----
>> @echo off
>>
>> cd /d "%~dp0\bin"
>>
>> bash --login -i
>> -----
>
> An errorlevel check is IMO mandatory after a cd command. Otherwise 
> another bash in the PATH might be started if the directory does not 
> exist.
> Hmm... therefore it is also better to change the last line to:
>
>   .\bash --login -i
>
> The directory change is intentionally done with two cd commands to 
> avoid possible problems with cmd variants (on Win10 "%~dp0" expands to 
> a path with trailing backslash).
If someone submits a patch to change cygwin.bat, please also add a 
command to clear $TERM on that occasion, in order to avoid trouble if 
cygwin.bat is started from a terminal:
set TERM=

Thomas

--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: Proposal for new cygwin.bat which is independent from install directory
  2016-08-27 13:23   ` Christian Franke
@ 2016-08-27 16:28     ` Andrey Repin
  2016-08-30 14:41       ` Corinna Vinschen
  0 siblings, 1 reply; 18+ messages in thread
From: Andrey Repin @ 2016-08-27 16:28 UTC (permalink / raw)
  To: Christian Franke, cygwin

Greetings, Christian Franke!

> Andrey Repin wrote:
>> ...
>> Why so complicated?
>>
>> @START "" /B "%~dp0bin\mintty.exe" -
>>
>> Done.

> Possibly not. This does not run bash in current console. It starts a new 
> mintty Window.

Who in their right mind would want a bogus native console?
You? Ok, you can change it to

    "%~dp0bin\bash.exe" --login -i

if you so desire.


-- 
With best regards,
Andrey Repin
Saturday, August 27, 2016 19:10:40

Sorry for my terrible english...


--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: Proposal for new cygwin.bat which is independent from install directory
  2016-08-27 13:13     ` Christian Franke
  2016-08-27 16:20       ` Bengt Larsson
  2016-08-27 16:20       ` Thomas Wolff
@ 2016-08-27 16:35       ` Andrey Repin
  2016-08-28  4:57         ` Christian Franke
  2 siblings, 1 reply; 18+ messages in thread
From: Andrey Repin @ 2016-08-27 16:35 UTC (permalink / raw)
  To: Christian Franke, cygwin

Greetings, Christian Franke!

>> Also don't see why so complicated. While staying in the console, how
>> about:
>> -----
>> @echo off
>>
>> cd /d "%~dp0\bin"
>>
>> bash --login -i
>> -----

> An errorlevel check is IMO mandatory after a cd command.

Absolutely unnecessary.
--login will change the CWD either way, and if it fail to execute, it will
fail either way.
Do NOT include redundant error handling "just because you can", or to report
to the user.
Only include error handling, if you have a plan to recover from error
condition, otherwise the scripting engine will report the error on its own,
you don't need to do anything special for that.

> Otherwise
> another bash in the PATH might be started if the directory does not exist.

That's because you're doing it wrong.

> Hmm... therefore it is also better to change the last line to:

>    .\bash --login -i

"%~dp0bin\bash.exe" --login -i

> The directory change is intentionally done with two cd commands to avoid 
> possible problems with cmd variants (on Win10 "%~dp0" expands to a path 
> with trailing backslash).

It ALWAYS expands into a path with trailing slash.
Read CALL /? and note the combining rules for modifiers.


-- 
With best regards,
Andrey Repin
Saturday, August 27, 2016 19:05:19

Sorry for my terrible english...


--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: Proposal for new cygwin.bat which is independent from install directory
  2016-08-27 16:35       ` Andrey Repin
@ 2016-08-28  4:57         ` Christian Franke
  2016-08-28  7:18           ` Andrey Repin
  0 siblings, 1 reply; 18+ messages in thread
From: Christian Franke @ 2016-08-28  4:57 UTC (permalink / raw)
  To: cygwin

Andrey Repin wrote:
>> Hmm... therefore it is also better to change the last line to:
>>     .\bash --login -i
> "%~dp0bin\bash.exe" --login -i

Changing the directory before bash is run is a security measure because 
the current directory may be in DLL search path. I guess this is one 
reason why the cygwin.bat file created by setup.exe also does this.


--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: Proposal for new cygwin.bat which is independent from install directory
  2016-08-28  4:57         ` Christian Franke
@ 2016-08-28  7:18           ` Andrey Repin
  2016-08-29 14:05             ` cyg Simple
  0 siblings, 1 reply; 18+ messages in thread
From: Andrey Repin @ 2016-08-28  7:18 UTC (permalink / raw)
  To: Christian Franke, cygwin

Greetings, Christian Franke!

> Andrey Repin wrote:
>>> Hmm... therefore it is also better to change the last line to:
>>>     .\bash --login -i
>> "%~dp0bin\bash.exe" --login -i

> Changing the directory before bash is run is a security measure because 
> the current directory may be in DLL search path.

And?

> I guess this is one reason why the cygwin.bat file created by setup.exe also
> does this.

I'm starting an application by its full path.


-- 
With best regards,
Andrey Repin
Saturday, August 27, 2016 20:42:53

Sorry for my terrible english...


--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: Proposal for new cygwin.bat which is independent from install directory
  2016-08-28  7:18           ` Andrey Repin
@ 2016-08-29 14:05             ` cyg Simple
  2016-08-29 17:14               ` Andrey Repin
  0 siblings, 1 reply; 18+ messages in thread
From: cyg Simple @ 2016-08-29 14:05 UTC (permalink / raw)
  To: cygwin



On 8/27/2016 1:44 PM, Andrey Repin wrote:
> Greetings, Christian Franke!
> 
>> Andrey Repin wrote:
>>>> Hmm... therefore it is also better to change the last line to:
>>>>     .\bash --login -i
>>> "%~dp0bin\bash.exe" --login -i
> 
>> Changing the directory before bash is run is a security measure because 
>> the current directory may be in DLL search path.
> 
> And?
> 
>> I guess this is one reason why the cygwin.bat file created by setup.exe also
>> does this.
> 
> I'm starting an application by its full path.
> 
> 

So...  It doesn't make it any more correct than Christian's method which
is what I prefer.  IIRC older versions of Windows required the change
directory to execute Cygwin properly.

-- 
cyg Simple

--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: Proposal for new cygwin.bat which is independent from install directory
  2016-08-29 14:05             ` cyg Simple
@ 2016-08-29 17:14               ` Andrey Repin
  2016-08-30 17:47                 ` cyg Simple
  0 siblings, 1 reply; 18+ messages in thread
From: Andrey Repin @ 2016-08-29 17:14 UTC (permalink / raw)
  To: cyg Simple, cygwin

Greetings, cyg Simple!



> On 8/27/2016 1:44 PM, Andrey Repin wrote:
>> Greetings, Christian Franke!
>> 
>>> Andrey Repin wrote:
>>>>> Hmm... therefore it is also better to change the last line to:
>>>>>     .\bash --login -i
>>>> "%~dp0bin\bash.exe" --login -i
>> 
>>> Changing the directory before bash is run is a security measure because 
>>> the current directory may be in DLL search path.
>> 
>> And?
>> 
>>> I guess this is one reason why the cygwin.bat file created by setup.exe also
>>> does this.
>> 
>> I'm starting an application by its full path.
>> 
>> 

> So...  It doesn't make it any more correct than Christian's method which
> is what I prefer.  IIRC older versions of Windows required the change
> directory to execute Cygwin properly.

How much "older"? Win'95? It is no longer supported.


-- 
With best regards,
Andrey Repin
Monday, August 29, 2016 16:57:44

Sorry for my terrible english...


--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: Proposal for new cygwin.bat which is independent from install directory
  2016-08-27 16:28     ` Andrey Repin
@ 2016-08-30 14:41       ` Corinna Vinschen
  0 siblings, 0 replies; 18+ messages in thread
From: Corinna Vinschen @ 2016-08-30 14:41 UTC (permalink / raw)
  To: cygwin

[-- Attachment #1: Type: text/plain, Size: 945 bytes --]

On Aug 27 19:12, Andrey Repin wrote:
> Greetings, Christian Franke!
> 
> > Andrey Repin wrote:
> >> ...
> >> Why so complicated?
> >>
> >> @START "" /B "%~dp0bin\mintty.exe" -
> >>
> >> Done.
> 
> > Possibly not. This does not run bash in current console. It starts a new 
> > mintty Window.
> 
> Who in their right mind would want a bogus native console?
> You? Ok, you can change it to
> 
>     "%~dp0bin\bash.exe" --login -i
> 
> if you so desire.

The Cygwin.bat script is specificially for this task, running a Cygwin
shell from the console.  This is still desired in some scenarios,
especially when mixing Cygwin and native tools sometimes, this is why
we never removed it.  If you want to run mintty, just use the shortcut
already created by setup.


Corinna

-- 
Corinna Vinschen                  Please, send mails regarding Cygwin to
Cygwin Maintainer                 cygwin AT cygwin DOT com
Red Hat

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 819 bytes --]

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: Proposal for new cygwin.bat which is independent from install directory
  2016-08-26 17:56 Proposal for new cygwin.bat which is independent from install directory Christian Franke
  2016-08-26 19:38 ` Andrey Repin
@ 2016-08-30 15:43 ` Corinna Vinschen
  2016-08-31 11:41   ` Christian Franke
  1 sibling, 1 reply; 18+ messages in thread
From: Corinna Vinschen @ 2016-08-30 15:43 UTC (permalink / raw)
  To: cygwin

[-- Attachment #1: Type: text/plain, Size: 1111 bytes --]

On Aug 26 18:23, Christian Franke wrote:
> Traditionally setup.exe creates the /cygwin.bat file as follows if C:\cygwin
> is the install directory:
> -----
> @echo off
> 
> C:
> chdir C:\cygwin\bin
> 
> bash --login -i
> -----
> 
> 
> The following should work since WinXP regardless of install directory:
> -----
> @echo off
> 
> cd /d %~dp0
> if errorlevel 1 exit /b 1
> cd bin
> if errorlevel 1 exit /b 1
> 
> bash --login -i
> -----
> 
> I would suggest to add something like the above as
> "/etc/defaults/cygwin.bat" to base-files package. The postinstall script
> should copy it to "/cygwin.bat" if new. The creation of this file could
> later be removed from setup.exe.

Apart from the complexity discussion, which is largly irrelevant, I like
the idea of moving this functionality out of setup and into a postinstall
script.

Please send patches.  I'm sure Achim will thoughtfully consider them.


Thanks,
Corinna

-- 
Corinna Vinschen                  Please, send mails regarding Cygwin to
Cygwin Maintainer                 cygwin AT cygwin DOT com
Red Hat

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 819 bytes --]

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: Proposal for new cygwin.bat which is independent from install directory
  2016-08-29 17:14               ` Andrey Repin
@ 2016-08-30 17:47                 ` cyg Simple
  2016-08-30 22:11                   ` Andrey Repin
  0 siblings, 1 reply; 18+ messages in thread
From: cyg Simple @ 2016-08-30 17:47 UTC (permalink / raw)
  To: cygwin

On 8/29/2016 9:58 AM, Andrey Repin wrote:
> Greetings, cyg Simple!
> 
> 
> 
>> On 8/27/2016 1:44 PM, Andrey Repin wrote:
>>> Greetings, Christian Franke!
>>>
>>>> Andrey Repin wrote:
>>>>>> Hmm... therefore it is also better to change the last line to:
>>>>>>     .\bash --login -i
>>>>> "%~dp0bin\bash.exe" --login -i
>>>
>>>> Changing the directory before bash is run is a security measure because 
>>>> the current directory may be in DLL search path.
>>>
>>> And?
>>>
>>>> I guess this is one reason why the cygwin.bat file created by setup.exe also
>>>> does this.
>>>
>>> I'm starting an application by its full path.
>>>
>>>
> 
>> So...  It doesn't make it any more correct than Christian's method which
>> is what I prefer.  IIRC older versions of Windows required the change
>> directory to execute Cygwin properly.
> 
> How much "older"? Win'95? It is no longer supported.
> 

It doesn't matter how old; it matters as a reason for the way it was
written in the first place.  It gives one pause as to making such a
change since it might not work in all cases where the change directory does.

-- 
cyg Simple

--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: Proposal for new cygwin.bat which is independent from install directory
  2016-08-30 17:47                 ` cyg Simple
@ 2016-08-30 22:11                   ` Andrey Repin
  0 siblings, 0 replies; 18+ messages in thread
From: Andrey Repin @ 2016-08-30 22:11 UTC (permalink / raw)
  To: cyg Simple, cygwin

Greetings, cyg Simple!

>>> On 8/27/2016 1:44 PM, Andrey Repin wrote:
>>>> Greetings, Christian Franke!
>>>>
>>>>> Andrey Repin wrote:
>>>>>>> Hmm... therefore it is also better to change the last line to:
>>>>>>>     .\bash --login -i
>>>>>> "%~dp0bin\bash.exe" --login -i
>>>>
>>>>> Changing the directory before bash is run is a security measure because 
>>>>> the current directory may be in DLL search path.
>>>>
>>>> And?
>>>>
>>>>> I guess this is one reason why the cygwin.bat file created by setup.exe also
>>>>> does this.
>>>>
>>>> I'm starting an application by its full path.
>>>>
>>>>
>> 
>>> So...  It doesn't make it any more correct than Christian's method which
>>> is what I prefer.  IIRC older versions of Windows required the change
>>> directory to execute Cygwin properly.
>> 
>> How much "older"? Win'95? It is no longer supported.
>> 

> It doesn't matter how old; it matters as a reason for the way it was
> written in the first place.  It gives one pause as to making such a
> change since it might not work in all cases where the change directory does.

I did made that pause. And I considered OS without cmd.exe not worth
consideration.


-- 
With best regards,
Andrey Repin
Tuesday, August 30, 2016 23:40:08

Sorry for my terrible english...


--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: Proposal for new cygwin.bat which is independent from install directory
  2016-08-30 15:43 ` Corinna Vinschen
@ 2016-08-31 11:41   ` Christian Franke
  0 siblings, 0 replies; 18+ messages in thread
From: Christian Franke @ 2016-08-31 11:41 UTC (permalink / raw)
  To: cygwin

[-- Attachment #1: Type: text/plain, Size: 1740 bytes --]

Corinna Vinschen wrote:
> On Aug 26 18:23, Christian Franke wrote:
>> Traditionally setup.exe creates the /cygwin.bat file as follows if C:\cygwin
>> is the install directory:
>> -----
>> @echo off
>>
>> C:
>> chdir C:\cygwin\bin
>>
>> bash --login -i
>> -----
>>
>>
>> The following should work since WinXP regardless of install directory:
>> -----
>> @echo off
>>
>> cd /d %~dp0
>> if errorlevel 1 exit /b 1
>> cd bin
>> if errorlevel 1 exit /b 1
>>
>> bash --login -i
>> -----
>>
>> I would suggest to add something like the above as
>> "/etc/defaults/cygwin.bat" to base-files package. The postinstall script
>> should copy it to "/cygwin.bat" if new. The creation of this file could
>> later be removed from setup.exe.
> Apart from the complexity discussion, which is largly irrelevant, I like
> the idea of moving this functionality out of setup and into a postinstall
> script.
>
> Please send patches.  I'm sure Achim will thoughtfully consider them.

Attached is a patch for current base-files package. Tested on WinXP and 
Win10. $TERM is cleared as suggested by Thomas Wolff.

Cygwin.bat is now somewhat shorter because meantime I found an old WinXP 
VM to test backward compatibility of "new" CMD syntax.

After applying the patch, please run "unix2dos 
.../etc/defaults/Cygwin.bat". BAT files with '\n' line endings run 
properly even on XP, but could not be edited with older versions of notepad.

There is no need to change setup.exe because it runs postinstall scripts 
before creating a still missing Cygwin.bat.

Please note one break of backward compatibility: The new Cygwin.bat 
preserves %CD% of parent CMD instead of changing to Cygwin's bin 
directory. Could possibly be considered as a feature.

Thanks,
Christian


[-- Attachment #2: base-files-4.2-4-Cygwin.bat.patch --]
[-- Type: text/x-patch, Size: 909 bytes --]

diff -Nru cygwin-base-files-4.2-4-1ffe2dd.orig/etc/defaults/Cygwin.bat cygwin-base-files-4.2-4-1ffe2dd/etc/defaults/Cygwin.bat
--- cygwin-base-files-4.2-4-1ffe2dd.orig/etc/defaults/Cygwin.bat	1970-01-01 01:00:00.000000000 +0100
+++ cygwin-base-files-4.2-4-1ffe2dd/etc/defaults/Cygwin.bat	2016-08-30 08:55:42.883139300 +0200
@@ -0,0 +1,4 @@
+@echo off
+setlocal enableextensions
+set TERM=
+cd /d "%~dp0bin" && .\bash --login -i
diff -Nru cygwin-base-files-4.2-4-1ffe2dd.orig/etc/preremove/base-files-manifest.lst cygwin-base-files-4.2-4-1ffe2dd/etc/preremove/base-files-manifest.lst
--- cygwin-base-files-4.2-4-1ffe2dd.orig/etc/preremove/base-files-manifest.lst	2015-09-26 09:31:45.000000000 +0200
+++ cygwin-base-files-4.2-4-1ffe2dd/etc/preremove/base-files-manifest.lst	2016-08-30 08:57:15.584588800 +0200
@@ -1,3 +1,4 @@
+Cygwin.bat
 etc/profile.d/lang.sh
 etc/profile.d/lang.csh
 etc/profile.d/tzset.sh



[-- Attachment #3: Type: text/plain, Size: 218 bytes --]

--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple

^ permalink raw reply	[flat|nested] 18+ messages in thread

end of thread, other threads:[~2016-08-31  5:35 UTC | newest]

Thread overview: 18+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-08-26 17:56 Proposal for new cygwin.bat which is independent from install directory Christian Franke
2016-08-26 19:38 ` Andrey Repin
2016-08-27 11:40   ` Bengt Larsson
2016-08-27 13:13     ` Christian Franke
2016-08-27 16:20       ` Bengt Larsson
2016-08-27 16:20       ` Thomas Wolff
2016-08-27 16:35       ` Andrey Repin
2016-08-28  4:57         ` Christian Franke
2016-08-28  7:18           ` Andrey Repin
2016-08-29 14:05             ` cyg Simple
2016-08-29 17:14               ` Andrey Repin
2016-08-30 17:47                 ` cyg Simple
2016-08-30 22:11                   ` Andrey Repin
2016-08-27 13:23   ` Christian Franke
2016-08-27 16:28     ` Andrey Repin
2016-08-30 14:41       ` Corinna Vinschen
2016-08-30 15:43 ` Corinna Vinschen
2016-08-31 11:41   ` Christian Franke

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).