Page 1 of 1

How do I excecute a batch file without call?

Posted: 03 Feb 2017 09:52
by TheHunterManX
I am trying to create a command for command prompt. I am making it using batch. How do I make it return to the previous batch file without using call?
ex.
Test.bat

Code: Select all

@echo off
example1 test
pause
echo test2
pause

example1.bat

Code: Select all

echo %1
pause
exit /b 0

it echo's test, then pauses once, then closes. It doesn't echo test2. What should I replace exit with so it returns? I have a much more script than this one, so please don't say stuff like "just use call!" or "just add it in the batch file!" or "just program it in a different language!".

Re: How do I excecute a batch file without call?

Posted: 03 Feb 2017 10:00
by Squashman
I don't know of any other way. That is the nature of cmd.exe.

Re: How do I excecute a batch file without call?

Posted: 03 Feb 2017 10:42
by Aacini
This method emulates the behavior of CALL command:

test.bat:

Code: Select all

@echo off
setlocal
if defined retAddr goto %retAddr%
set "retAddr=ret1"
example1 test
:ret1
pause
echo test2
pause

example1.bat:

Code: Select all

echo %1
pause
test

Please, don't reply with "this is too much complicated!". The CALL command exists for a reason...

Antonio

Re: How do I excecute a batch file without call?

Posted: 03 Feb 2017 14:22
by ShadowThief
I think a better question is "why can't you use call?"

This question is then followed by a slightly horrified "oh dear God, are you using actual DOS?"

Re: How do I excecute a batch file without call?

Posted: 03 Feb 2017 15:36
by Squashman
Only other way I can think of doing it.

test.bat

Code: Select all

@echo off
TITLE %~nx0
start "" /wait example1.bat test
echo %errorlevel%
echo test2
pause

example1.bat

Code: Select all

@echo off
TITLE %~nx0
echo %1
pause
exit 2

Re: How do I excecute a batch file without call?

Posted: 03 Feb 2017 15:37
by penpen
You could also use "cmd /c" or "cmd /q /c" instead of call:

Code: Select all

@echo off
cmd /q /cexample1 test
pause
echo test2
pause


penpen

Re: How do I excecute a batch file without call?

Posted: 03 Feb 2017 16:35
by Aspidiske
I do not know what you have in mind, but I already used script to simulate a command line, you can create the commands but you never leave the script

Code: Select all

:start
@set line=
@cd
@set /p line=
@if "%line%"=="mycommand" goto mycommand
%line%
@goto start
:mycommand
@echo.mycommand ok
@goto start


or

Code: Select all

@echo off
:start
set line=
set /p line=
if "%line%"=="mycommand" goto mycommand
%line%
goto start
:mycommand
echo.mycommand ok
goto start