X-Recipient: archive-cygwin AT delorie DOT com DomainKey-Signature: a=rsa-sha1; c=nofws; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:date:from:to:subject:message-id:reply-to :references:mime-version:content-type:in-reply-to; q=dns; s= default; b=txx/QxDtSZWoRCRnpon9ZaK78t31W/bfvFAG2uKFK9QsvTQ2wgkRo 9qrT5PgAVlZlk07Jqut07VR3K8vBM+XzbmmyHG116bMnLRXpOnnYe6kWfnXyF/wS DPr2vrZeaVE5DbgpfbrV/liyOb8vmEIJPplbmi+pI++JeS3E5tSQEA= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:date:from:to:subject:message-id:reply-to :references:mime-version:content-type:in-reply-to; s=default; bh=nKbMDw5CvgK29lRy6qxxnEHfyXQ=; b=UcTyDIELw0gJNsfgETYDiHwgRHgo jzD8Y8w1167lfmVR4s2ZiU6iJktSCRBRShhMvAUJM7zoDbGuxdmz1seHjnkXUdFb 3d39uhkqwjlGoQQEVRNxZkVm5tVtWsjlrUiOXG0GUyzp3g+A9xe6KzWiBu4mVKm4 8vvWoYBIK6Pn124= Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: cygwin-owner AT cygwin DOT com Mail-Followup-To: cygwin AT cygwin DOT com Delivered-To: mailing list cygwin AT cygwin DOT com Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-104.1 required=5.0 tests=AWL,BAYES_00,GOOD_FROM_CORINNA_CYGWIN,RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 spammy= X-HELO: mout.kundenserver.de Date: Wed, 7 Aug 2019 16:31:21 +0200 From: Corinna Vinschen To: cygwin AT cygwin DOT com Subject: Re: How to query the value of %SystemDrive% in an empty environment? Message-ID: <20190807143121.GD11632@calimero.vinschen.de> Reply-To: cygwin AT cygwin DOT com Mail-Followup-To: cygwin AT cygwin DOT com References: <089bb243-1dbb-048a-39aa-f54048a39e26 AT ssi-schaefer DOT com> <0f9d219c-a9ae-237a-afcf-9dcc5a13bc01 AT SystematicSw DOT ab DOT ca> <20190807111943 DOT GC11632 AT calimero DOT vinschen DOT de> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="Rnz0oC2K6vQ5doJs" Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.11.3 (2019-02-01) --Rnz0oC2K6vQ5doJs Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Aug 7 14:41, Michael Haubenwallner wrote: > On 8/7/19 1:19 PM, Corinna Vinschen wrote: > > On Aug 7 13:08, Michael Haubenwallner wrote: > >> On 8/7/19 4:33 AM, Brian Inglis wrote: > >>> On 2019-08-06 09:20, Michael Haubenwallner wrote: > >>>> using 'env -i' to create an empty environment, the SYSTEMROOT and WI= NDIR > >>>> environment variables are preserved (or recreated): > >>>> $ /usr/bin/env -i /usr/bin/env > >>>> SYSTEMROOT=3DC:\Windows > >>>> WINDIR=3DC:\Windows > >>>> And with cygpath, there is the -A, -D, -H, -O, -P, -S, -W and even -= F flags > >>>> to query the values for various directories. > >>>> Now what I've failed to find is how to query the value for the "Syst= emDrive" > >>>> environment variable. > >>>> The problem behind is that I'm using "vswhere.exe" to locate some Vi= sual Studio > >>>> environment from within some scripts run via 'env -i', causing vswhe= re.exe to > >>>> create a directory named "%SystemDrive%" in the current working dire= ctory: > >>>> So I better ensure the SystemDrive environment variable is set for v= swhere.exe. > >>>> Any ideas? > >>> > >>> There is a reg entry: > >>> > >>> $ head > >>> /proc/registry/HKEY_LOCAL_MACHINE/SYSTEM/CurrentControlSet/Control/Sy= stemBootDevice; > >>> echo > >>> multi(0)disk(0)rdisk(1)partition(3) > >>> > >>> but how do you convert that to a device letter? > >>> > >>> SYSTEMDRIVE is a dynamic env var created at startup pointing to the b= oot drive > >>> letter. It is not instantiated anywhere else as far I could find. A n= umber of > >>> low level reg entries use that env var. Only option is to pass it thr= ough: > >> > >> Heck, even CreateEnvironmentBlock() relies on SYSTEMROOT env var being= set, > >> otherwise returning things like ProgramData=3D"%SystemDrive%\ProgramDa= ta". > >=20 > > So, what does this have to do with Cygwin in case you clean out the > > environment? This is nothing you want to do if you plan to start > > a non-Cygwin executable. >=20 > I do prefer to have full control over the environment, recreating the nee= ded > vars from the registry or similar, because I did have too much troubles w= ith > polluted environment already. This also applies to setting up some wrapp= er > around the MSVC toolchain, that provide the vswhere.exe helper these days. >=20 > Actually I would have been fine it was obvious enough to locate SYSTEMDRI= VE, > much like SYSTEMROOT and WINDIR are available via cygpath, or reading oth= er > specific environment variable values from /proc/registry/. >=20 > As SYSTEMROOT and WINDIR are preserved already, even if they are available > via cygpath as well, also preserving SYSTEMDRIVE simply feels suitable he= re. > And even more since I found this commit, which seems to intent the same: > https://cygwin.com/git/gitweb.cgi?p=3Dnewlib-cygwin.git;a=3Dcommitdiff;h= =3D1f99dd3ecf3252517363ec8f0fec4b0a95706f31 >=20 > Anyway: If it is possible to map above SystemBootDevice registry value to > SYSTEMDRIVE, I would be fine as well. You can just as easily get it from SYSTEMROOT, as outlined before. SYSTEMROOT is the system directory located on the system boot drive so just strip off the path and keep the drive. Corinna --=20 Corinna Vinschen Cygwin Maintainer --Rnz0oC2K6vQ5doJs Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAEBCAAdFiEEoVYPmneWZnwT6kwF9TYGna5ET6AFAl1K4LkACgkQ9TYGna5E T6Cfng/+NdZsJ93lxzeHe34e9i14TPjIehhyXObvGN3iplSbjJCwzNHFGQ9FTKZI LUYWYIkfeAZdrjx/HUjuKQSJHmkE/eCtvGwW6pAmsELoG0FtOrE64TCyjpRRuUJT bvU6CJYmLSZ1/5+X0Sy7X5o373wv0AIlTM1eWKBUvH98Sf/bPNIw7NK2ehlmoxHO JS/j2PNFoo7jxMsXWBlggdpkdDweCdsThhL4E2dWI2ZjJm9UwPGFkdO6q+eLU6jV KVYOhbTsTklWqm/Pb2hWnh1n9QGcerOLoUG8DIgxUJaB+6zgfowUDczRX7MA5AN9 WSnR2FS17PuRIr1FVjwG/QbZJM0ywzYMKuFlepy5xXmCszHMT4Pk0htP8qjsXON7 Bv85UoeUXTMPVhAivtcnGurWzy17TJ5B16WuBxDQq7Vdt2aAMNUkIH13Wlu5LR8Z KXGB4tQozfPM002q/2A6Rg/AJR67PPI3FVF/nOypfvI1DbPQ/EgU47YHguOX8m2Q Tw1lFzQBYtwP+Kk2DFNMWNdfPG8e6sE5IzVvghViNK3oNjvhKCz3S0z+MFtJC2DW ULq/bNzBFNA0ExWEHEpTviHIA9XR8/+V0JBHIZdHANIRHGmeSsR3njjPtEQg3c4s QnVmGolhiBa1VLEIr30iTG9NSs5xu+YP3rsbT/m+itkqX5lo+yQ= =iBA5 -----END PGP SIGNATURE----- --Rnz0oC2K6vQ5doJs--