If I can understand your question: you need a method that allows the batch version of the script to determine if it was called using the call command from another batch of script. The following 33939966test.bat script shows a possible approach: force use with the required parameter "^%%%%" as follows:
@ECHO OFF >NUL if "%~1" == "" goto :USAGE if "%~1" == "^^%%" echo call from another script %* & goto :GOOD if "%~1" == "^%%%%" echo from another script %* & goto :USAGE if "%~1" == "^^%%%%%%%%" echo call from command line %* & goto :USAGE if "%~1" == "^%%%%%%%%" echo from command line %* & goto :USAGE echo(wrong 1st parameter %%*=%* goto :USAGE :GOOD echo( rem echo original %%*=%* shift /1 rem echo shifted %%*=%* :: Note that `shift` does not affect %* ::::::::::::::::::::::::::::::::::::::: :: Useful code begins here goto :eof :USAGE echo USAGE: CALL %~nx0 "^%%%%%%%%" [parameters] echo( rem the 1st parameter must be: rem "CARET followed by four PERCENT SIGNS" including all " DOUBLE QUOTES goto :eof
The output from the command line:
==> rem cmd copy&paste start ==> ECHO OFF >NUL 33939966test.bat "C&D pay 21 % VAT" "^=caret" %OS% %%OS%% wrong 1st parameter %*="C&D pay 21 % VAT" "^=caret" Windows_NT %Windows_NT% USAGE: CALL 33939966test.bat "^%%%%" [parameters] call 33939966test.bat "^%%%%" "C&D pay 21 % VAT" "^=caret" %OS% %%OS%% call from command line "^^%%%%" "C&D pay 21 % VAT" "^^=caret" Windows_NT %Windows_NT% USAGE: CALL 33939966test.bat "^%%%%" [parameters] 33939966test.bat "^%%%%" "C&D pay 21 % VAT" "^=caret" %OS% %%OS%% from command line "^%%%%" "C&D pay 21 % VAT" "^=caret" Windows_NT %Windows_NT% USAGE: CALL 33939966test.bat "^%%%%" [parameters] ECHO ON >NUL ==> rem cmd copy&paste end
Conclusion from the caller:
==> 33939966myCaller.bat ==> call 33939966test.bat "C&D pay 21 %% VAT" "^=caret" Windows_NT %OS% wrong 1st parameter %*="C&D pay 21 % VAT" "^^=caret" Windows_NT Windows_NT USAGE: CALL 33939966test.bat "^%%%%" [parameters] ==> call 33939966test.bat "^%%" "C&D pay 21 %% VAT" "^=caret" Windows_NT %OS% call from another script "^^%" "C&D pay 21 % VAT" "^^=caret" Windows_NT Windows_NT ==> 33939966test.bat "^%%" "C&D pay 21 % VAT" "^=caret" Windows_NT %OS% from another script "^%%" "C&D pay 21 % VAT" "^=caret" Windows_NT %OS% USAGE: CALL 33939966test.bat "^%%%%" [parameters]
where 33939966myCaller.bat reads as follows (copy and paste the paste):
@ECHO ON call 33939966test.bat "C&D pay 21 %%%% VAT" "^=caret" %OS% %%OS%% @ECHO ON call 33939966test.bat "^%%%%" "C&D pay 21 %%%% VAT" "^=caret" %OS% %%OS%% @ECHO ON 33939966test.bat "^%%%%" "C&D pay 21 %% VAT" "^=caret" %OS% %%OS%% @ECHO OFF goto :eof rem cmd copy&paste start ECHO OFF >NUL 33939966test.bat "C&D pay 21 % VAT" "^=caret" %OS% %%OS%% call 33939966test.bat "^%%%%" "C&D pay 21 % VAT" "^=caret" %OS% %%OS%% 33939966test.bat "^%%%%" "C&D pay 21 % VAT" "^=caret" %OS% %%OS%% ECHO ON >NUL rem cmd copy&paste end
Please note that the above approach is not bulletproof, as we can present a false result from the command line:
==> 33939966test.bat "^^%" "C&D pay 21 % VAT" "^=caret" %OS% %%OS%% call from another script "^^%" "C&D pay 21 % VAT" "^=caret" Windows_NT %Windows_NT%
Perhaps combination of methods (goto) can help?
JosefZ
source share