SCRIPT help. for syntex problem

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
Rajnishjc_27
Posts: 21
Joined: 16 Aug 2019 23:35

SCRIPT help. for syntex problem

#1 Post by Rajnishjc_27 » 27 Aug 2019 01:02

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...

ShadowThief
Expert
Posts: 1160
Joined: 06 Sep 2013 21:28
Location: Virginia, United States

Re: SCRIPT help. for syntex problem

#2 Post by ShadowThief » 27 Aug 2019 03:08

Without seeing the context that this snippet is in, it's impossible to say. Please post all of the code.

Rajnishjc_27
Posts: 21
Joined: 16 Aug 2019 23:35

Re: SCRIPT help. for syntex problem

#3 Post by Rajnishjc_27 » 27 Aug 2019 03:23

ShadowThief wrote:
27 Aug 2019 03:08
Without seeing the context that this snippet is in, it's impossible to say. Please post all of the code.
code as below

@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

ShadowThief
Expert
Posts: 1160
Joined: 06 Sep 2013 21:28
Location: Virginia, United States

Re: SCRIPT help. for syntex problem

#4 Post by ShadowThief » 27 Aug 2019 05:29

You never enable delayed expansion anywhere, so !rc! doesn't mean anything to the interpreter.

Erzesel
Posts: 5
Joined: 25 Aug 2019 02:28
Location: Leipzig /DE

Re: SCRIPT help. for syntex problem

#5 Post by Erzesel » 27 Aug 2019 07:34

Your Code makes absolutely no sense.
  • 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
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

Post Reply