簡體   English   中英

將變量傳遞到批處理文件

[英]pass variables to batch file

我有一個需要使用批處理文件安裝應用程序的要求。 當我運行此批處理文件時,它會要求輸入,而該批處理文件在內部會調用一個Powershell腳本來詢問輸入,如果我為某些輸入按下回車鍵,它將采用默認值。

任何人都可以讓我知道如何將所有輸入存儲在文件中並將其傳遞到批處理文件嗎?它還應支持Powershell腳本以及默認值。

BATCHFILE.cmd

@echo off
setlocal EnableDelayedExpansion
set scriptsPath=%~dp0
set scriptsPathShort=%~dps0
set psPath=%windir%\System32\WindowsPowerShell\v1.0\powershell.exe

:params
set Path=%~1
set psVersion=0

if "!psVersion!" == "2.0" "!psPath!" -version !psVersion! -command "!scriptsPathShort!install\install-driver.ps1" '!Path!' '****'
if not !errorlevel! == 0 goto error 
goto end    

 install-driver.ps1
param 
(
    [string] $scriptsBasePath = $(throw "Missing parameter: scriptsBasePath"),
    [string] $Path = $(throw "Missing parameter: packagePath"),
    [string] $packageRootFolder = $(throw "Missing parameter: packageRootFolder")
)
$configFileName = "install.config"

**install.config**

<Param name="ClientDir" required="1"
                label="Client Directory" 
                desc="Choose a unique name which will be used by the application to create folder in which client files will be stored" />

        <Param mode="adv" name="lPswdEncryptionMode" required="1" defaultValue="2" 
                label="Password Encryption Mode" /> 
<Param componentType="webserver" name="WebsiteName" required="1" defaultValue="Default Web Site" 
                label="Website Name" 
                desc="Enter site name under which the website component will be installed" cloud="1" />

這只是一段代碼而已。 它調用了一個配置文件,其中我沒有幾個參數。 誰能讓我知道如何傳遞變量?

這是我將config / ini文件中的變量收集到powershell中的方法。

$SETTINGS = Get-Content .\install.config

$scriptsBasePath = $SETTINGS[0]
$Path = $SETTINGS[1]
$packageRootFolder = $SETTINGS[2]

如果install.config不在同一目錄中,請替換完整路徑。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM