批处理文件:与另一个实例中的批处理脚本打开的Shell实例进行交互

jmlesfrite

我的目标是让一个python脚本调用一个批处理脚本,再调用一个cmd文件来加​​载环境变量并用它们执行一些命令。

我的批处理脚本的第一行是调用cmd文件来加​​载环境变量。第二行是使用此环境并传递参数的命令。

我的问题是,第一行打开一个新的Shell实例,脚本的第二行在尚未加载我的环境的第一个Shell实例中执行。

我应该如何在新实例中使用我的环境继续执行命令?

cmd /k "C:\Program Files (x86)\Microsoft GSDK\Command Prompts\GamingDesktopVars.cmd" GamingDesktopVS2017
wdapp unregister myAppName

这是命令文件:

@echo off
REM ====================================================================
REM Set path variables
REM ==========================================================================

IF /I "%1"=="GamingDesktopVS2017" (
  CALL :SetVS2017
)ELSE (
  ECHO You must specify GamingDesktopVS2017 on the command line.
  EXIT /B 1
)

IF "%GRDKEDITION%"=="" (
    IF NOT "%2"=="" (
       SET GRDKEDITION=%2
    )ELSE (
        REM Get the most recent GXDK edition installed.
        CALL :GetLatestGRDK
    )
)

IF %DTARGETVSVER% GEQ 15.0 (

    SET GRDKVSPRERELEASE=-prerelease

    REM Possible values include Microsoft.VisualStudio.Product.Professional,
    REM Microsoft.VisualStudio.Product.Community and Microsoft.VisualStudio.Product.Enterprise
    REM separated by spaces for multiple products.
    IF "%GRDKVSPRODUCTS%"=="" (
        IF NOT "%3"=="" (
            SET GRDKVSPRODUCTS= -products %3
        )
    ) ELSE (
        SET GRDKVSPRODUCTS= -products %GRDKVSPRODUCTS%
    )

    IF "%GRDKVSVERSION%"=="" (
        IF NOT "%4"=="" (
            IF NOT "%4"=="NOPRE" (
                SET GRDKVSVERSION= -version %4
            )
        )
    ) ELSE (
        SET GRDKVSVERSION= -version %GRDKVSVERSION%
    )

    IF "%GRDKVSNOPRERELEASE%"=="" (
        IF "%4"=="NOPRE" (
            SET GRDKVSPRERELEASE=
        )ELSE (
            IF "%5"=="NOPRE" (
                SET GRDKVSPRERELEASE=
            )
        )
    ) ELSE (
        SET GRDKVSPRERELEASE=
    )
)

IF "%GRDKEDITION%"=="" (
    REM If no GXDK edition found then assume Durango.
    SET XDKEDITION=000000
)

Echo Setting environment for using Microsoft Desktop %DTARGETVS% Gaming Tools
TITLE Desktop %DTARGETVS% Gaming Command Prompt

IF "%GamingSDK%"=="" (
    CALL :GetGSDKInstallPath
)
IF "%GamingSDK%"=="" (
    ECHO Microsoft Gaming Development Kit directory is not found on this machine.
    EXIT /B 1
)

IF NOT "%GRDKEDITION%"=="000000" (
    IF "%GamingGRDKBuild%"=="" (
        CALL :GetGRDKBuildInstallPath
    )

    IF "%GamingGRDKEditionVersionFriendlyName%"=="" (
        CALL :GetGRDKEditionVersionFriendlyName
    )

    IF "%GamingDesktopExtensionSdkBuild%"=="" (
        CALL :GetGamingDesktopExtensionSdkPath
    )
)

IF NOT "%GRDKEDITION%"=="000000" (
    IF "%GamingGRDKBuild%"=="" (
        ECHO Microsoft Gaming Development Kit build for %GRDKEDITION% is not found on this machine.
        EXIT /B 1
    )

    IF "%GamingDesktopExtensionSdkBuild%"=="" (
        ECHO Microsoft Desktop Development Kit SDK Extensions for %GRDKEDITION% are not found on this machine.
        EXIT /B 1
    )

    IF NOT "%GamingGRDKEditionVersionFriendlyName%"=="" (
        TITLE %GamingGRDKEditionVersionFriendlyName% Desktop %DTARGETVS% Gaming Command Prompt
    )
)

IF "%WindowsSDKDir%" == "" (
    CALL :GetWindowsSDKDir
)

IF "%WindowsSDKDir%"=="" (
    ECHO Warning: Windows Software Development Kit directory is not found on this machine.
)

IF NOT "%WindowsSDKDir%" == "" (
    if "%WindowsSDKVersion%" == "" (
        CALL :GetWindowsSDKVersion
    )
)

IF NOT "%WindowsSDKDir%" == "" (
    IF "WindowsSDKVersion"=="" (
        ECHO Warning: Windows Software Development Kit version not specified.
    ) else (
        Set "WindowsIncludeRoot=%WindowsSDKDir%Include\%WindowsSDKVersion%\"
        Set "WindowsLibRoot=%WindowsSDKDir%Lib\%WindowsSDKVersion%\"
    )
)

IF "%VSInstallDir%"=="" (
    CALL :GetVSInstallDir
)
IF "%VSInstallDir%"=="" (
    ECHO Warning: %DTARGETVS% is not found on this machine.
)

IF "%VCInstallDir%"=="" (
    if "%VCToolsVersion%"=="" (
        CALL :GetVCToolsVersion
    )

    CALL :GetVCInstallDir
)
IF "%VCInstallDir%"=="" (
    ECHO Warning: %DTARGETVS% VC is not found on this machine.
)

IF "%FrameworkDir%"=="" (
    CALL :GetFrameworkDir
)
IF "%FrameworkDir%"=="" (
    ECHO Warning: .Net Framework is not found on this machine.
)

IF "%FrameworkVersion%"=="" (
    CALL :GetFrameworkVer
)
IF "%FrameworkVersion%"=="" (
    IF EXIST "%FrameworkDir%v4.0.30319" (
        SET "FrameworkVersion=v4.0.30319"
    )
)

IF "%MSBuildInstallDir15%"=="" (
    CALL :GetMSBuildInstallDir15
)

REM ==========================================================================
REM Set path 
REM ==========================================================================

IF EXIST "%VSInstallDir%Team Tools\Performance Tools" (
    SET "PATH=%VSInstallDir%Team Tools\Performance Tools\x64;%VSInstallDir%Team Tools\Performance Tools;%PATH%"
)

IF EXIST "%VSInstallDir%" (
    SET "PATH=%VSInstallDir%Common7\Tools;%VSInstallDir%Common7\IDE;%PATH%"
)

IF EXIST "%VCInstallDir%" (
    SET "PATH=%VSInstallDir%Common7\IDE\VC\vcpackages\;%PATH%"
)

IF EXIST "%FrameworkDir%" (
    SET "PATH=%FrameworkDir%%FrameworkVersion%;%PATH%"
)
SET "PATH=%GamingSDK%bin;%PATH%"

IF NOT "%GRDKEDITION%"=="000000" (
    SET "PATH=%GamingGRDKBuild%bin;%PATH%"
)

IF EXIST "%PIXPath%" (
    SET "PATH=%PIXPath%;%PATH%"
)

REM Normal compiler for VS2017/GXDL.
SET "PATH=%VCInstallDir%bin\Hostx64\x64;%PATH%"

IF EXIST "%WindowsSDKDir%bin\%WindowsSDKVersion\%x64" (
    SET "PATH=%WindowsSDKDir%bin\%WindowsSDKVersion%\x64;%PATH%"
)

REM ==========================================================================
REM Set Include
REM ==========================================================================

IF EXIST "%VCInstallDir%" (
    SET "INCLUDE=%VCInstallDir%INCLUDE;%INCLUDE%"
)
SET "INCLUDE=%GamingGRDKBuild%gamekit\include;%INCLUDE%"

IF EXIST "%WindowsIncludeRoot%" (
    SET "INCLUDE=%WindowsIncludeRoot%um;%WindowsIncludeRoot%shared;%WindowsIncludeRoot%winrt;%WindowsIncludeRoot%cppwinrt;%WindowsIncludeRoot%ucrt;%INCLUDE%"
)

REM ==========================================================================
REM Set Lib
REM ==========================================================================
SET "LIB=%GamingGRDKBuild%gamekit\lib\amd64;%VCInstallDir%\lib\x64;%LIB%"

IF EXIST "%WindowsLibRoot%" (
    SET "LIB=%WindowsLibRoot%um\x64;%WindowsLibRoot%ucrt\x64;%LIB%"
)

REM ==========================================================================
REM Set LibPath
REM ==========================================================================
IF EXIST "%VCInstallDir%" (
    SET "LIBPATH=%VCInstallDir%LIB\x64;%LIBPATH%"
)
IF EXIST "%FrameworkDir%" (
    SET "LIBPATH=%FrameworkDir%%FrameworkVersion%;%LIBPATH%"
)

SET "LIBPATH=%GamingDesktopExtensionSdkBuild%references\CommonConfiguration\Neutral;%LIBPATH%"

SET Platform=Gaming.Desktop.x64

REM ==========================================================================
REM Set the MSBuild path after everything else so that it appears first in the
REM path. VS2017 must not accidentally target msbuild.exe in the .NET
REM Framework since it stopped shipping there in dev12 and later.
REM ==========================================================================
  SET "PATH=%MSBuildInstallDir15%;%PATH%"

SET CommandPromptType=Native
SET VisualStudioVersion=%DTARGETVSVER%
CD /D "%GamingSDK%bin"

GOTO :EOF

:GetVSInstallDir

set VSWHERELOCATION="%ProgramFiles(x86)%\Microsoft Visual Studio\Installer\vswhere.exe"

if not exist %VSWHERELOCATION% (
    Set LegacyVSLocation="true"
)

FOR /f "tokens=1,2*" %%a in ('reg query "HKLM\Software\Microsoft\GSDK\%GRDKEDITION%\GRDK" /v "VSIXEditionID" /reg:32 2^>NUL') DO SET GamingGXDKVSIXID=%%c

IF defined LegacyVSLocation (
    FOR /f "tokens=1,2*" %%a in ('reg query "HKLM\Software\Microsoft\VisualStudio\SxS\VS7" /v "%DTARGETVSVER%" /reg:32 2^>NUL') DO SET VSInstallDir=%%c
) ELSE (
    FOR /f "usebackq tokens=1* delims=: " %%i in (`%VSWHERELOCATION% -latest -requires %GamingGXDKVSIXID% %GRDKVSVERSION% %GRDKVSPRODUCTS% %GRDKVSPRERELEASE%`) do (
        IF /i "%%i"=="installationPath" set VSInstallDir=%%j
    )
)

IF defined VSInstallDir IF not "!VSInstallDir:~-1!"=="\" set VSInstallDir=%VSInstallDir%\

GOTO :EOF

:GetVCToolsVersion
set VCDefaultConfigFile="%VSInstallDir%VC\Auxiliary\Build\Microsoft.VCToolsVersion.default.txt"

if not exist %VCDefaultConfigFile% (
    ECHO Warning: Could not find default VC++ tools config file %VCDefaultConfigFile%.
    GOTO :EOF
)

for /F %%A in ('type %VCDefaultConfigFile%') do set VCToolsVersion=%%A

if "%VCToolsVersion%"=="" (
    ECHO Warning: Could not determine default VC++ tools version.
)
GOTO :EOF

:GetVCInstallDir
if "%VCToolsVersion%" NEQ "" (
    SET "VCInstallDir=%VSInstallDir%VC\Tools\MSVC\%VCToolsVersion%\"
)ELSE (
    ECHO Warning: Could not set VC Install Directory.
)
GOTO :EOF

:GetLatestGRDK
REM Sets GRDKEDITION to latest GRDK's edition number.
FOR /f "tokens=1,2*" %%a in ('reg query "HKLM\Software\Microsoft\GSDK" /v "GRDKLatest" /reg:32 2^>NUL') DO SET GRDKEDITION=%%c
GOTO :EOF

:GetGRDKBuildInstallPath
REM Sets GamingGRDKBuild to location of Gaming GRDK build tools.
FOR /f "tokens=1,2*" %%a in ('reg query "HKLM\Software\Microsoft\GSDK\%GRDKEDITION%\GRDK" /v "InstallPath" /reg:32 2^>NUL') DO SET GamingGRDKBuild=%%c
GOTO :EOF

:GetGamingDesktopExtensionSdkPath
REM Sets  GamingDesktopExtensionSdkBuild to the location of the current GXDK edition's extension SDK root.
FOR /f "tokens=1,2*" %%a in ('reg query "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Microsoft SDKs\Gaming.Desktop.x64.%GRDKEDITION%\v10.0" /v "InstallationFolder" /reg:32 2^>NUL') DO SET GamingDesktopExtensionSdkBuild=%%c
GOTO :EOF

:GetGRDKEditionVersionFriendlyName
REM Sets GamingGRDKEditionVersionFriendlyName to the friendly version name of the selected build tools.
FOR /f "tokens=1,2*" %%a in ('reg query "HKLM\Software\Microsoft\GSDK\%GRDKEDITION%\GRDK" /v "EditionVersionFriendlyName" /reg:32 2^>NUL') DO SET GamingGRDKEditionVersionFriendlyName=%%c
GOTO :EOF

:GetGSDKInstallPath
REM Sets GamingXDK to location of GXDK
FOR /f "tokens=1,2*" %%a in ('reg query "HKLM\Software\Microsoft\GSDK" /v "GRDKInstallPath" /reg:32 2^>NUL') DO SET GamingSDK=%%c
GOTO :EOF

:GetMSBuildInstallDir15
REM Sets MSBuild15 directory.
IF /I "%DPLATFORM%"=="VS2017" (
  SET "MSBuildInstallDir15=%VSInstallDir%MSBuild\15.0\Bin\;%PATH%"
)
GOTO :EOF

:GetFrameworkDir
FOR /f "tokens=1,2*" %%a in ('reg query "HKLM\Software\Microsoft\.NETFramework" /v "InstallRoot" /reg:32 2^>NUL') DO SET FrameworkDir=%%c
GOTO :EOF

:GetFrameworkVer
FOR /f "tokens=1,2*" %%a in ('reg query "HKLM\Software\Microsoft\VisualStudio\SxS\VC7" /v "FrameworkVer32" /reg:32 2^>NUL') DO SET FrameworkVersion=%%c
GOTO :EOF

:SetVS2017
SET DPLATFORM=VS2017
SET DTARGETVS=Visual Studio 2017
SET DTARGETVSVER=15.0
GOTO :EOF

:GetWindowsSDKDir
If exist "%GamingSDK%\%GRDKEDITION%\WindowsSDK" (
 Set "WindowsSDKDir=%GamingSDK%\%GRDKEDITION%\WindowsSDK\"
) else (
    @REM Get Windows 10 SDK installed folder
    for /F "tokens=1,2*" %%i in ('reg query "HKLM\SOFTWARE\Wow6432Node\Microsoft\Microsoft SDKs\Windows\v10.0" /v "InstallationFolder"') DO (
        if "%%i"=="InstallationFolder" (
            SET WindowsSdkDir=%%~k
        )
    )
)

GOTO :EOF

:GetWindowsSDKVersion
REM From VS 2017 winsdk.bat GetWin10SdkDirHelper
@REM get windows 10 sdk version number
setlocal enableDelayedExpansion

@REM Due to the SDK installer changes beginning with the 10.0.15063.0 (RS2 SDK), there is a chance that the
@REM Windows SDK installed may not have the full set of bits required for all application scenarios.
@REM We check for the existence of a file we know to be included in the "App" and "Desktop" portions
@REM of the Windows SDK, depending on the Developer Command Prompt's -app_platform configuration.
@REM If "windows.h" (UWP) or "winsdkver.h" (Desktop) are not found, the directory will be skipped as
@REM a candidate default value for [WindowsSdkDir].
set __check_file=winsdkver.h
if /I "%VSCMD_ARG_APP_PLAT%"=="UWP" set __check_file=Windows.h

if not "%WindowsSdkDir%"=="" for /f %%i IN ('dir "%WindowsSdkDir%include\" /b /ad-h /on') DO (
    @REM Skip if Windows.h|winsdkver (based upon -app_platform configuration) is not found in %%i\um.  
    if EXIST "%WindowsSdkDir%include\%%i\um\%__check_file%" (
        set result=%%i
        if "!result:~0,3!"=="10." (
            set SDK=!result!
            if "!result!"=="%VSCMD_ARG_WINSDK%" set findSDK=1
        )
    )
)

if "%findSDK%"=="1" set SDK=%VSCMD_ARG_WINSDK%
endlocal & set WindowsSDKVersion=%SDK%

if not "%VSCMD_ARG_WINSDK%"=="" (
  @REM if the user specified a version of the SDK and it wasn't found, then use the
  @REM user-specified version to set environment variables.

  if not "%VSCMD_ARG_WINSDK%"=="%WindowsSDKVersion%" (
    if "%VSCMD_DEBUG%" GEQ "1" echo [DEBUG:%~nx0] specified /winsdk=%VSCMD_ARG_WINSDK% was not found or was incomplete
    set WindowsSDKVersion=%VSCMD_ARG_WINSDK%
    set WindowsSDKNotFound=1
  )
) else (
  @REM if no full Windows 10 SDKs were found, unset WindowsSDKDir and exit with error.

  if "%WindowsSDKVersion%"=="" (
    set WindowsSDKNotFound=1
    set WindowsSDKDir=
  )
)

GOTO :EOF

:end
不是我

如果您编辑蝙蝠(GamingDesktopVS2017.cmd),然后添加:


@echo off && cd /d "c:\folder\to\where\the\bat\are\"
SET "DPLATFORM=VS2017
SET "DTARGETVS=Visual Studio 2017"
SET "DTARGETVSVER=15.0"

并运行/调用此命令:

echo=exit|cmd /v /k GamingDesktopVS2017.cmd wdapp unregister myAppName

为什么要使用cmd /k


关于“ C:\ Program Files(x86)\ Microsoft GSDK \ Command Prompts \ GamingDesktopVars.cmd”执行以下操作:

rem ::  the bat only check if your are passing this argument :GamingDesktopVS2017 
rem ::  if positive, then set same variable that you can add in your bat :

IF /I "%1"=="GamingDesktopVS2017" (

CALL :SetVS2017 => call label :SetVS2017 )ELSE (

ECHO You must specify GamingDesktopVS2017 on the command line.

EXIT /B 1

)


和标签执行此操作:

:SetVS2017
SET DPLATFORM=VS2017
SET DTARGETVS=Visual Studio 2017
SET DTARGETVSVER=15.0
GOTO :EOF

只需将以上设置移到您的蝙蝠上即可!

对不起,我的英文有限

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

从另一个批处理文件调用一个批处理,并从外部批处理中设置内部批处理文件参数

如何在另一个批处理文件中调用一个批处理文件?

循环调用另一个批处理文件的批处理文件

调用另一个批处理文件的调用批处理文件失败

使批处理文件等待另一个批处理文件

如何从另一个批处理文件在批处理文件中写入管道(|)?

批处理-如何关闭从另一个批处理文件启动的批处理文件

从另一个打开批处理文件(包括Java)

Windows 批处理文件以提升的权限启动另一个批处理

从另一个批处理文件启动一个批处理文件只会打开CMD

编写批处理文件:批处理将命令插入到另一个基于cmd的程序中

如何在批处理文件中传递来自另一个 perl 脚本的输入

如何从其他目录中的另一个批处理文件中的一个批处理文件中启动exe文件?

仅当从另一个批处理文件调用批处理文件时,如何才能处理该批处理文件?

如何从另一个批处理脚本中杀死正在执行的批处理脚本?

如何通过另一个批处理文件更新一个批处理文件中的值

Windows批处理文件中的数字大于或小于另一个

获取另一个变量中的批处理文件变量的值

无法在另一个批处理文件中回显自删除命令

在Windows批处理文件中,您可以链式执行不是另一个批处理文件的内容吗?

如何使用批处理制作另一个带有变量的批处理文件?

使用批处理文件复制文件名并附加另一个文件

Windows批处理文件,循环浏览文件夹中的文件以创建参数列表以传递到另一个脚本

在 Notepad++ 打开的文件夹中打开一个批处理文件

将截断的文件名传递到另一个批处理文件

批处理文件以将文件夹移动到另一个

如何使批处理文件移动另一个文件?

从另一个文件夹运行批处理文件

如何写入一个批处理文件以告诉它写入另一个批处理文件