Uma criança cmd instance herda todas as variáveis de ambiente da variável pai. Prova: vamos criar dois scripts em lote:
Test1.bat
@setlocal
@set _batch
@set "_batchParentName=%~nx0"
@set "_batchParentPath=%~dp0"
@set "_batchParentSpec=< LSS > GTR & amper | pipe"
start "%~n0" cmd /C call "test.bat" "%_batchParentSpec%" %* ^& pause
@set _batch
Test.bat
@setlocal
@set _batch
@echo %~n0: %%* = %*
Saída da instância parent cmd :
d:\bat>test1.bat first "1<2" third
Environment variable _batch not defined
d:\bat>start "test1" cmd /C call "test.bat" "< LSS > GTR & amper | pipe" first "1<2" third
& pause
_batchParentName=test1.bat
_batchParentPath=D:\bat\
_batchParentSpec=< LSS > GTR & amper | pipe
d:\bat>
Criança cmd instance output de test.bat :
_batchParentName=test1.bat
_batchParentPath=D:\bat\
_batchParentSpec=< LSS > GTR & amper | pipe
test: %* = "< LSS > GTR & amper | pipe" first "1<2" third
Press any key to continue . . .
Observe a sintaxe de comando start com "title" :
START "title" [/D path] [options] "command" [parameters]
Always include a TITLE this can be a simple string like "My Script" or just a pair of empty quotes "". According to the Microsoft documentation, the title is optional, but depending on the other options chosen you can have problems if it is omitted.
Garanta que o comando start não contenha a opção /I (de start /? ):
/I The new environment will be the original environment passed
to the cmd.exe and not the current environment.
Para eliminar outra eventualidade das alterações do ambiente filho, inclua a alteração /D em cmd da seguinte forma:
start "test1" cmd /D /C call "test.bat"
Como por cmd /? :
/D Disable execution of AutoRun commands from registry