我有一個powershell腳本P.ps1
,它在內部調用批處理腳本B1.bat
和B2.bat
。在運行時將值傳遞給Powershell的批處理文件
P.ps1
代碼如下:
B1.bat
$a= Read-host "Choose 1 or 2:"
B2.bat
Write-host "End of code"
B1.bat
代碼是:從的powershell script.i.e
echo "Hello World"
B2.bat
需要輸入。 $a
已被髮送到B2.bat
@ECHO OFF
SET var = a
rem This "a" is coming from "P.ps1"
ECHO We're working with %var%
使用
$Env:Var=$a
在批處理不要把空格等號周圍的一組命令。空格將成爲變量名稱和內容的一部分。 – LotPings哦,謝謝!我會編輯。 –