DosTips.com

A Forum all about DOS Batch
It is currently 27 Feb 2017 19:04

All times are UTC-06:00




Post new topic  Reply to topic  [ 7 posts ] 
Author Message
PostPosted: 03 Feb 2017 09:52 
Offline

Joined: 14 Aug 2015 05:59
Posts: 44
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!".


Top
   
PostPosted: 03 Feb 2017 10:00 
Offline
Expert

Joined: 23 Dec 2011 13:59
Posts: 3470
I don't know of any other way. That is the nature of cmd.exe.


Top
   
PostPosted: 03 Feb 2017 10:42 
Offline
Expert

Joined: 06 Dec 2011 22:15
Posts: 1291
Location: México City, México
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


Top
   
PostPosted: 03 Feb 2017 14:22 
Offline

Joined: 06 Sep 2013 21:28
Posts: 624
Location: Virginia, United States
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?"


Top
   
PostPosted: 03 Feb 2017 15:36 
Offline
Expert

Joined: 23 Dec 2011 13:59
Posts: 3470
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


Top
   
PostPosted: 03 Feb 2017 15:37 
Offline

Joined: 23 Jun 2013 06:15
Posts: 1227
Location: Germany
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


Top
   
PostPosted: 03 Feb 2017 16:35 
Offline

Joined: 30 Oct 2016 09:48
Posts: 5
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


Top
   
Display posts from previous:  Sort by  
Post new topic  Reply to topic  [ 7 posts ] 

All times are UTC-06:00


Who is online

Users browsing this forum: Bing [Bot], Yahoo [Bot] and 10 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Limited