1.

Solve : linking batch files?

Answer»

what I’m trying to do is to create a system variable LEJOS_HOME = c:\lejos and in the next step I’m added %LEJOS_HOME%/bin to the END of the system variable PATH but it cant be added until LEJOS_HOME exists and for some reason it wont exist until the batch is closed, also having them in 2 different batch files and calling each on MANUALLY will work but having them called one after another from a 3rd batch file will not work. is there any way to have a batch file close it self then call the next one? or any other suggestions?Quote from: ahamelin on February 05, 2008, 09:11:34 AM

... is there any way to have a batch file close it self then call the next one?


Regarding just this part of your post:

Yes.
Don't use the call command. Simply have batch1 execute batch2 the same as it would any other program.
When this happens, batch1 ceases to RUN, and batch2 takes over - unlike when batch2 is run with the call command. The call command allows batch1 to continue to run, and batch 2 to run within it. When batch2 ends, control reverts back to batch1 on the same line as batch2 ended.

Example:
Code: [Select]rem save this and name it batch1.bat
@echo off
cls
echo This is batch1
echo.
pause
call batch2
echo.
pause
echo Now back in batch1
echo.
pause
Code: [Select]@echo off

rem save this and name it batch2.bat

echo Now in batch2
echo.

You'll see what happens with the above two silly and simple batch files.

Now edit batch1.bat to:
Code: [Select]@echo off
cls
echo This is batch1
echo.
pause

batch2

echo.
pause
echo Now back in batch1
echo.
pause

and you'll see that the last part of batch1 is never run.


Quote
what I’m trying to do is to create a system variable LEJOS_HOME = c:\lejos and in the next step I’m added %LEJOS_HOME%/bin to the end of the system variable PATH but it cant be added until LEJOS_HOME exists and for some reason it wont exist until the batch is closed

I'm not sure it works that way.

Code: [Select]@echo off
set lejos_home=c:\lejos
path=%path%;%lejos_home%

The new path will be in effect until the window closes. Perhaps if you posted your code it will be easier to see what you've done.



all RIGHTY willy W's way of doing it the second batch file just runs in the command prompt that the first one did so the command prompt is not closing there for the variables are not being set permanently so that doesn't work but thanks anyways ^.^
and for sidewinder (lover the halo reference ) i will post my code and try to make it a little more clear what I'm trying to do thanks again

batch file 1
Code: [Select]@ECHO OFF
CLS
ECHO Starting the batch file
WindowsXP-KB838079-SupportTools-ENU.exe
cd MINDSTORMS NXT Driver v1.02
setup.exe
cd ..
xcopy /s /i lejos_nxj\*.* c:\lejos_nxj
copy LeJOSNXTExtension.jar C:\BlueJ\lib\extensions
ECHO Now run Step2:
PAUSE
EXIT

batch 2
Code: [Select]@ECHO OFF
SETX LEJOS_HOME "C:\lejos_nxj" -m
ECHO Now run Step3:
PAUSE
EXIT
batch 3
Code: [Select]@ECHO OFF

SETX Path "%PATH%;%LEJOS_HOME%\bin" -m

ECHO Now run Step4:

PAUSE

EXIT

there are actually 4 batch files , these are the first 3, but i just mentioned the 2nd and 3rd because they were the easyest to describe. anyways the 2nd and 3rd ones could probably be fixed by also using a set .... as well as the setx so they get set locally as well as in the system , setx sets the system variables in the system but CMD can not see that variable until the cmd that set them is closed. and you need the windows update that's installed in the first batch file to get setx working in the first place. any ideas?I probably would combine all the batch files, use set locally for the run, and use setx at the end of the file to get the values in the machine environment.

This would allow you to build all the environment strings so that this line would work:

SETX Path "%PATH%;%LEJOS_HOME%\bin" -m

Hope this helps.





Discussion

No Comment Found