Your Code makes absolutely no sense.
- you are using Batch variables in Syntax of delayed Expansion (!myVar!) without enabling this syntax by:
- Outside of command blocks, this is not necessary. the specification of the variable with %myVar% is sufficient.]
the lines after: error are complete fantasy syntax and do not fulfill any function except to trigger an error message itself
but my SET "%~2=!rc!" output parameter not return anything, it should return 1
You try to assign the value of another variable to an argument variable. Even if you were to use the correct syntax for %rc%, that would be impossible.
I have no idea what you mean by "output parameter" and what you want to return where.
Maybe you just explain your project and what should happen in the result. (In normal human language)
but my glass ball tells me ....
something about?...
the caller:
My1.cmd
Code: Select all
@echo off
echo now executing %~nx0
rem get an Errorlevel back
call "my2.cmd" "Experiment 1" "Error Return"
echo back in %~nx0
echo There is Errorlevel %errorlevel% returned
echo:
rem now to get a user defined Variable back from 2nd Batch
call "my2.cmd" "Experiment 2" "Variable Return"
echo back in %~nx0
echo %myNewVar% returned
echo:
rem now to get only Texoutput from 2nd Batch
for /f "tokens=*" %%a in ('""my2.cmd" "Experiment 3" "Text Return""') do (
echo sended Text: %%a
set "myOtherVar=%%a"
)
echo as last Line: #%myOtherVar%# was retuened
pause
exit /b
the receiver and retuner:
my2.cmd
Code: Select all
@echo off
echo now executing %~nx0
echo the 1st given Parameter is %1
echo the 2nd given Parameter is %2
if "%~2"=="Error Return" goto error
if "%~2"=="Variable Return" goto varRet
if "%~2"=="Text Return" goto txtRet
exit /b 0
:error
echo somwat #%1 ...
rem return an Errornumber
exit /b 4712
:varRet
rem return an Variable
set "myNewVar=Hallo from the Others"
exit /b
:txtRet
rem simply write some textoutput
echo This is a Letter from Space
exit /b
These are the 3 most common ways... (ok, the 3rd is probably rather strange)
edit:
i had forgotten...
testl_return_of_intenal_call.cmd :
Code: Select all
@echo off
set rc=1
if %rc% equ 1 call :error Arg1 "Something Text"
echo subroutine :error retuned Errorlevel %errorlevel%
echo subroutine :error retuned #%myVar%# at variable %%myVar%%
pause
exit /b
:error
echo Failed with validation #%1.
set "myVar=%~2"
exit /b 123456