delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2008/03/31/10:46:09

X-Recipient: archive-cygwin AT delorie DOT com
X-Spam-Check-By: sourceware.org
Message-ID: <47F1069B.3080102@hdfgroup.org>
Date: Mon, 31 Mar 2008 10:43:23 -0500
From: Scott Wegner <swegner AT hdfgroup DOT org>
User-Agent: Thunderbird 2.0.0.12 (Windows/20080213)
MIME-Version: 1.0
To: cygwin AT cygwin DOT com
Subject: Re: Remove Cygwin Path for Called Batch Script
References: <47E8FE86 DOT 9020405 AT hdfgroup DOT org> <47E90794 DOT 3010406 AT sbcglobal DOT net> <47E909C3 DOT 3010408 AT hdfgroup DOT org> <loom DOT 20080326T182436-900 AT post DOT gmane DOT org>
In-Reply-To: <loom.20080326T182436-900@post.gmane.org>
X-IsSubscribed: yes
Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm
List-Id: <cygwin.cygwin.com>
List-Subscribe: <mailto:cygwin-subscribe AT cygwin DOT com>
List-Archive: <http://sourceware.org/ml/cygwin/>
List-Post: <mailto:cygwin AT cygwin DOT com>
List-Help: <mailto:cygwin-help AT cygwin DOT com>, <http://sourceware.org/ml/#faqs>
Sender: cygwin-owner AT cygwin DOT com
Mail-Followup-To: cygwin AT cygwin DOT com
Delivered-To: mailing list cygwin AT cygwin DOT com

Kurt Franke wrote:
> Scott Wegner <swegner <at> hdfgroup.org> writes:
> 
>> Greg Chicares wrote:
>>> On 2008-03-25 13:30Z, Scott Wegner wrote:
>>>> I am trying to create a "wrapper" Cygwin bash script to add 
>>>> functionality to an existing Windows batch script.  In my Cygwin script, 
>>>> I would like to call the batch file with something like:
>>>>
>>>> ...
>>>> cmd.exe /k batch-script.bat params
>>>> ...
>>>>
>>>> Calling the script in this fashion seems to generally work (in that the 
>>>> script executes).  However, I have trouble because the Cygwin path is 
>>>> prepended to the Windows path in the batch script.  As a result, trying 
>>>> to use the Windows "find" use Cygwin's instead.
>>> If you write
>>>   %SystemRoot%\system32\find
>>> in the batch file, then you'll get the msw "find" whether or not
>>> any Cygwin directory is on your path.
>> Hi Greg,
>>
>> Thanks for the quick reply.  This is a feasible solution.  However, I'd 
>> rather find a solution where the batch script can remain "unaware" of 
>> its Cygwin context.  Once I get things working, I plan on creating bash 
>> script wrappers for many Windows batch scripts, so I'd like to make the 
>> changes in the Cygwin environment, rather than editing each batch script 
>> individually.
>>
>> I'll keep looking at let you know if I find anything.
>>
>> Scott
>>
>>
> 
> Hi Scott,
> 
> you may just remove all path components from PATH which are part of cygwin.
> 
> I use the following bash function to do those removing since long years ago:
> 
> rmpc()
> {
>   local C=$2
>   local R=""
>   local OIFS="$IFS"
>   IFS="$IFS:"
>   set -- $1
>   IFS="$OIFS"
>   for i in "$@"
>   do
>     if [ "x$i" != "x$C" ]
>     then
>       if [ "x$R" != "x" ]
>       then
>         R="$R:$i"
>       else
>         R="$i"
>       fi
>     fi
>   done
>   echo $R
> }
> 
> to work correctly make sure your wrapper script starts with bash in magic line -
> #! /bin/bash
> for example but not
> #! /bin/sh 
> because when invoked as bourne shell necessary functionality may be missed
> 
> you may add this function directly after the magic line for invocation
> 
> 
> then just before calling your dos batch scripts remove the unwanted
> path components from PATH
> 
> you shouldn't do this earlier in your code because no cygwin applications
> and scripts are found after this unless they are hashed by bash in a
> pervious call
> 
> 
> PATH=`rmpc $PATH /bin`
> PATH=`rmpc $PATH /usr/bin`
> 
> you may remove any path component this way
> 
> PATH=`rmpc $PATH .`     # remove .
> PATH=`rmpc $PATH ""`    # remove blank path components
> 
> 
> caution: this mechanism remove all multiple occurences of a componente
> from PATH
> 
> 
> when returned from your dos batch script you are lacking the most cygwin
> functionality.
> to get it again you have to save the PATH previous to the changes:
> 
> SAVE_PATH=$PATH
> 
> and just restore it after the dos script returned:
> 
> PATH=$SAVE_PATH
> 

Hi Kurt,

Thanks for the reply (as well as others who have contributed).  This 
looks like it will fit my needs perfectly.  I'll give it a try and post 
back if I have any more trouble.

Thanks!
Scott

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

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

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019