How do I excecute a batch file without call?

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
TheHunterManX
Posts: 54
Joined: 14 Aug 2015 05:59

How do I excecute a batch file without call?

#1 Post by TheHunterManX » 03 Feb 2017 09:52

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

Squashman
Expert
Posts: 4465
Joined: 23 Dec 2011 13:59

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

#2 Post by Squashman » 03 Feb 2017 10:00

I don't know of any other way. That is the nature of cmd.exe.

Aacini
Expert
Posts: 1885
Joined: 06 Dec 2011 22:15
Location: México City, México
Contact:

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

#3 Post by Aacini » 03 Feb 2017 10:42

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

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

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

#4 Post by ShadowThief » 03 Feb 2017 14:22

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?"

Squashman
Expert
Posts: 4465
Joined: 23 Dec 2011 13:59

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

#5 Post by Squashman » 03 Feb 2017 15:36

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

penpen
Expert
Posts: 1991
Joined: 23 Jun 2013 06:15
Location: Germany

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

#6 Post by penpen » 03 Feb 2017 15:37

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

Aspidiske
Posts: 7
Joined: 30 Oct 2016 09:48

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

#7 Post by Aspidiske » 03 Feb 2017 16:35

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

Post Reply