Hi.
if !rc! equ 1 goto error
:error
echo Failed with validation #%1%.
SET %~2=!rc!
exit /b
but my SET "%~2=!rc!" output parameter not return anything, it should return 1
help...
SCRIPT help. for syntex problem
Moderator: DosItHelp
-
- Expert
- Posts: 1166
- Joined: 06 Sep 2013 21:28
- Location: Virginia, United States
Re: SCRIPT help. for syntex problem
Without seeing the context that this snippet is in, it's impossible to say. Please post all of the code.
-
- Posts: 21
- Joined: 16 Aug 2019 23:35
Re: SCRIPT help. for syntex problem
code as belowShadowThief wrote: ↑27 Aug 2019 03:08Without seeing the context that this snippet is in, it's impossible to say. Please post all of the code.
@echo off
set rc=1
if !rc! equ 1 goto error
:error
echo Failed with validation #%1%.
SET %~2=!rc!
exit /b
am getting blank in arguments 2 , instead of 1
-
- Expert
- Posts: 1166
- Joined: 06 Sep 2013 21:28
- Location: Virginia, United States
Re: SCRIPT help. for syntex problem
You never enable delayed expansion anywhere, so !rc! doesn't mean anything to the interpreter.
Re: SCRIPT help. for syntex problem
Your Code makes absolutely no sense.
the lines after: error are complete fantasy syntax and do not fulfill any function except to trigger an error message itself
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
the receiver and retuner:
my2.cmd
These are the 3 most common ways... (ok, the 3rd is probably rather strange)
edit:
i had forgotten...
testl_return_of_intenal_call.cmd :
- you are using Batch variables in Syntax of delayed Expansion (!myVar!) without enabling this syntax by:
Code: Select all
setlocal enableDelayedExpansion
- Outside of command blocks, this is not necessary. the specification of the variable with %myVar% is sufficient.]
Code: Select all
set rc=1
if %rc% equ 1 goto error
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.but my SET "%~2=!rc!" output parameter not return anything, it should return 1
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
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
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