Avoid Command termination in batch

April 8, 2011 at 19:55:06
Specs: Windows XP SP3, 2Gb
Hello,
I have a task: execute 2 commands: com1 and com2. I want that command com2 will be executed only if com1 succeeded. I use batch like this:
@echo off
set x=com1
%x%
IF %ERRORLEVEL% NEQ 0 (EXIT)
set y=com2
%y%
The problem is that execution never get to line 'if' ... and check for condition. It looks that after %x% batch always exit and doesn't give the option to check for condition.
Could someone give an idea how to prevent to terminate batch to exit after %x% and force to go to 'if' statement?
Thanks in advance

See More: Avoid Command termination in batch

Report •


#1
April 9, 2011 at 04:28:44
[1] Are com1 & 2 BATs, EXEs or what?

[2] Using a reserved word or defined device as a command name is almost always a bad idea.


=====================================
Life is too important to be taken seriously.

M2


Report •

#2
April 9, 2011 at 04:59:19
I have no doubt that the problem is caused by com1. If my com1 is like
set com1=copy x y
then it works fine.
But my actual com1 is a program and it looks like:
set x=c:\myProgram\xyz
%x%
It looks that after execution com1 immediately exit and doesn't go to the next line.
How to prevent it and force to go to the next line in my batch?
thanks

Report •

#3
April 9, 2011 at 05:07:16
You can't force it to continue executing, but you can force the window to stay open.

See #3: http://www.computing.net/answers/pr...

Also "\\.\%cd%\com1"


Report •

Related Solutions

#4
April 9, 2011 at 05:33:43
@echo off & setLocal enableDELAYedeXpansioN

set x=c:\myProgram\xyz
!x!
echo !ERRORLEVEL!


=====================================
Life is too important to be taken seriously.

M2


Report •


Ask Question