From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 8461 invoked by alias); 7 Aug 2019 12:41:07 -0000 Mailing-List: contact cygwin-help@cygwin.com; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: cygwin-owner@cygwin.com Mail-Followup-To: cygwin@cygwin.com Received: (qmail 8454 invoked by uid 89); 7 Aug 2019 12:41:07 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-5.7 required=5.0 tests=AWL,BAYES_00,RCVD_IN_DNSWL_NONE,SPF_PASS autolearn=ham version=3.3.1 spammy= X-HELO: atfriesa01.ssi-schaefer.com Received: from atfriesa01.ssi-schaefer.com (HELO atfriesa01.ssi-schaefer.com) (193.186.16.100) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Wed, 07 Aug 2019 12:41:05 +0000 Received: from samail03.wamas.com (HELO mailhost.salomon.at) ([172.28.33.235]) by atfriesa01.ssi-schaefer.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 07 Aug 2019 14:41:02 +0200 Received: from fril0049.wamas.com ([172.28.42.244]) by mailhost.salomon.at with esmtp (Exim 4.77) (envelope-from ) id 1hvLFW-0004gR-9q; Wed, 07 Aug 2019 14:41:02 +0200 Subject: Re: How to query the value of %SystemDrive% in an empty environment? To: cygwin@cygwin.com References: <089bb243-1dbb-048a-39aa-f54048a39e26@ssi-schaefer.com> <0f9d219c-a9ae-237a-afcf-9dcc5a13bc01@SystematicSw.ab.ca> <20190807111943.GC11632@calimero.vinschen.de> From: Michael Haubenwallner Openpgp: preference=signencrypt Message-ID: Date: Wed, 07 Aug 2019 12:41:00 -0000 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.8.0 MIME-Version: 1.0 In-Reply-To: <20190807111943.GC11632@calimero.vinschen.de> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-SW-Source: 2019-08/txt/msg00103.txt.bz2 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 WINDIR >>>> environment variables are preserved (or recreated): >>>> $ /usr/bin/env -i /usr/bin/env >>>> SYSTEMROOT=C:\Windows >>>> WINDIR=C:\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 "SystemDrive" >>>> environment variable. >>>> The problem behind is that I'm using "vswhere.exe" to locate some Visual Studio >>>> environment from within some scripts run via 'env -i', causing vswhere.exe to >>>> create a directory named "%SystemDrive%" in the current working directory: >>>> So I better ensure the SystemDrive environment variable is set for vswhere.exe. >>>> Any ideas? >>> >>> There is a reg entry: >>> >>> $ head >>> /proc/registry/HKEY_LOCAL_MACHINE/SYSTEM/CurrentControlSet/Control/SystemBootDevice; >>> 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 boot drive >>> letter. It is not instantiated anywhere else as far I could find. A number of >>> low level reg entries use that env var. Only option is to pass it through: >> >> Heck, even CreateEnvironmentBlock() relies on SYSTEMROOT env var being set, >> otherwise returning things like ProgramData="%SystemDrive%\ProgramData". > > 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. I do prefer to have full control over the environment, recreating the needed vars from the registry or similar, because I did have too much troubles with polluted environment already. This also applies to setting up some wrapper around the MSVC toolchain, that provide the vswhere.exe helper these days. Actually I would have been fine it was obvious enough to locate SYSTEMDRIVE, much like SYSTEMROOT and WINDIR are available via cygpath, or reading other specific environment variable values from /proc/registry/. As SYSTEMROOT and WINDIR are preserved already, even if they are available via cygpath as well, also preserving SYSTEMDRIVE simply feels suitable here. And even more since I found this commit, which seems to intent the same: https://cygwin.com/git/gitweb.cgi?p=newlib-cygwin.git;a=commitdiff;h=1f99dd3ecf3252517363ec8f0fec4b0a95706f31 Anyway: If it is possible to map above SystemBootDevice registry value to SYSTEMDRIVE, I would be fine as well. Thanks! /haubi/ -- 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