繁体   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