Вы можете передать в batch1.bat переменных в качестве аргументов batch2.bat.
arg_batch1.bat
@echo off
cls
set file_var1=world
set file_var2=%computername%
call arg_batch2.bat %file_var1% %file_var2%
:: Note that after batch2.bat runs, the flow returns here, but since there's
:: nothing left to run, the code ends, giving the appearance of ending with
:: batch2.bat being the end of the code.
arg_batch2.bat
@echo off
:: There should really be error checking here to ensure a
:: valid string is passed, but this is just an example.
set arg1=%~1
set arg2=%~2
echo Hello, %arg1%! My name is %arg2%.
Если вам необходимо запустить сценарии одновременно, вы можете использовать временный файл.
file_batch1.bat
@echo off
set var=world
:: Store the variable name and value in the form var=value
:: > will overwrite any existing data in args.txt, use >> to add to the end
echo var1=world>args.txt
echo var2=%COMPUTERNAME%>>args.txt
call file_batch2.bat
file_batch2.bat
@echo off
cls
:: Get the variable value from args.txt
:: Again, there is ideally some error checking here, but this is an example
:: Set no delimiters so that the entire line is processed at once
for /f "delims=" %%A in (args.txt) do (
set %%A
)
echo Hello, %var1%! My name is %var2%.
Вы можете либо передать переменные batch1 в качестве аргументов в пакет b2, либо сохранить переменные во временном файле, если вам нужно одновременно запускать оба сценария. – SomethingDark
Не могли бы вы привести пример и того, и другого? –
Является ли batch2 подпроцессом batch1 или несвязанным процессом? – Magoo