This is the mail archive of the cygwin mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

RE: find the path for cygwin root from windows script


> From: bertrand marquis
> Sent: Thursday, June 17, 2004 4:26 PM

Comments inline below...

> Luc Hermitte a écrit:
>
> >Hello,
> >
> >* On Thu, Jun 17, 2004 at 11:12:00AM +0200, bertrand marquis
> <bertrand_marquis@yahoo.fr> wrote:
> >
> >
> >>   i need to be able to find where cygwin is install from a .bat script
> >>under windows to run cygwin programs.
> >>Does anyone has a solution to do that automaticaly ?
> >>
> >>
> >
> >    cygpath -m /
> >
> I agree that is working but only if your path is set correctly and to do
> that you need to know where cygwin has been installed
>
> >
> >However, this solution requires that cygwin directories are visible from
> >your $PATH. In other words, you won't really need to know where they are
> >installed.
> >
> >
> >
> Anyway i found a solution looking into the windows registry where this
> is writting when cygwin is installed.
> Here is an example which start an xterm.
>
> ::start of file xterm.bat
> @echo off
> SET DISPLAY=127.0.0.1:0.0
>
> REM Look for cygwin entry in windows registry
> REGEDIT /E %Temp%.\tmp-cygwin.reg "HKEY_LOCAL_MACHINE\SOFTWARE\Cygnus
> Solutions\Cygwin\mounts v2\/"> nul
>
> REM Check if something has been found
> if not exist %Temp%.\tmp-cygwin.reg goto EXITNOCYGWIN
>
> REM Get the native key from windows registry result
> FOR /F "tokens=1* delims==" %%A IN ('TYPE %Temp%.\tmp-cygwin.reg ^| FIND
> "native"') DO SET CYGWIN_ROOT=%%B> nul
>
> REM Remove quotes
> SET CYGWIN_ROOT=%CYGWIN_ROOT:"=%> nul
>
> REM Remove temporary file
> if exist %Temp%.\tmp-cygwin.reg del %Temp%.\tmp-cygwin.reg
>
> REM Check if we have found something
> if "%CYGWIN_ROOT%" == "" goto EXITNOCYGWIN
>
> REM Export Cygwin path
> SET
> PATH=.;%CYGWIN_ROOT%\bin;%CYGWIN_ROOT%\usr\X11R6\bin;%CYGWIN_ROOT%
> \opt\elinos\bin;%PATH%
>
> run xterm
>
> exit
>
> :EXITNOCYGWIN
> echo no cygwin entry has been found in registry
> pause
>
> ::end of file


Another way is to dynamically create a bat script that redefines
"CYGWIN_ROOT". e.g.

$ cat mkrtbat.sh
#!/bin/bash

echo -e >$(cygpath -u "c:\rt.bat") "set root=$(cygpath -m /)\n\r"
--
Then use "call C:\rt" in any bat script to get the ROOT variable set.

(Hmm... I tried to set "-quotes for root's value, but that creates problems
in bat scripts :-7 )

This ofcourse requires _one_ run of the above
 to take note of any changes.


>
> I only have two questions left:
> - is HKEY_LOCAL_MACHINE\SOFTWARE\Cygnus Solutions\Cygwin\mounts v2
> always the place where i can find the mounts in the registry
>
> - is there a way to check that there is actually a X server running on
> 127.0.0.1 from a windows script. As this if there isn't i could start one.


Check the output of
$ ps
before and after you've run "startx &". To give you the an idea;

$ ps | grep 'X11' | wc -l
      2
$ ps | grep 'X11'
  1880  1680  1680  1588  0  500 20:35:54 /usr/X11R6/bin/xinit
  1296  1880  1296  2444  0  500 20:35:54 /usr/X11R6/bin/XWin

Hmm... you'd better check your setup. I seem to have some kind of trouble
with my installation. There seems to be a dual start of "XWin" - leading to
a deadlock <sigh>...
 I haven't noticed this before, I hardly use X at all.


/Hannu E K Nevalainen, B.Sc. EE - 59+16.37'N, 17+12.60'E             --76-->

** on a mailing list; please keep replies on that particular list **

-- printf("LocalTime: UTC+%02d\n",(DST)? 2:1); --
--END OF MESSAGE--


--
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/


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]