Click here to Skip to main content
15,891,184 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
Hi,
I think, I've got an easy problem.. but can't solve it

I want to do a simple thing:

File 1:
"one.bat":
@echo off
echo One 
Two.bat
-------<here i="" want="" to="" get="" returned="" value...="">-------
echo The End
pause</here>


File 2:
"Two.bat":
@echo off
echo Two 
-------<here i="" want="" to="" return="" value="">-------
</here>




I tired:
EXIT /B 23 - and doesn't work..

[edit]Code blocks added, "Ignore HTML..." option disabled - OriginalGriff[/edit]
Posted
Updated 21-Mar-11 5:40am
v2

Been a while since I played with this...

one.Bat:
@echo off
echo one
call two.bat
if %errorlevel%==23 goto twentythree
echo unknown errolevel
goto end
:twentythree
echo Success!
:end


two.Bat:
@echo OFF
echo two
exit /B 23
If you just execute two.bat from within one.bat, then it will return to CMD when two exits, not to the same plave in one.bat - you need to use CALL two.bat
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 21-Mar-11 14:15pm    
Griff, a 5 for your answer. Just in case: do you know batch's procedures and call? They are available since NT (I think), much more robust way to work. Even in batch goto is unwanted! Please see my Answer for detail.
--SA
OriginalGriff 21-Mar-11 15:23pm    
Hi SA: yes I was aware of them! Nasty kludge in my opinion, could have been a lot better but that would have upset the batch purists at the time I think.
Wouldn't have solved the OP's problem, but they are a valid (if badly implemented) way to do things! 5 :laugh:
Sergey Alexandrovich Kryukov 21-Mar-11 23:32pm    
Thank you. Of course it is nasty, but better than nothing. I say, the benefits of batch file starts from the fact they are always available, do not require any installations. Those benefits and right after :-)
--SA
Use new batch feature instead:

call:proc parameter
goto:eof

:proc
    echo %1
goto:eof


The line "goto:oef" in proc actually does not go to the end of file but performs a return. The value of parameter is obtained inside proc as %1.

—SA
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900