Batch to run several files

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Message
Author
rfdr81
Posts: 25
Joined: 26 Mar 2013 04:29

Batch to run several files

#1 Post by rfdr81 » 07 Apr 2013 12:50

Hello i have this code:

Code: Select all

@echo off
rem *** jump to model according to PA number ***
set "pa"=
set /p "pa"=PA Number:

:PSAT1
:PSAT2
cd biostosh\bios1.exe

:PXLL1
cd biostosh\bios2.exe


the objective is to put in a USB drive in order to run the new bios for PC. Some models use the same bios file. This code works, but if i put the "PSAT1" goes to bios1.exe, and PXLL1 goes to the same file, when should go to bios2.exe.
Need help please

Endoro
Posts: 244
Joined: 27 Mar 2013 01:29
Location: Bozen

Re: Batch to run several files

#2 Post by Endoro » 07 Apr 2013 13:05

Try this:

Code: Select all

@echo off
rem *** jump to model according to PA number ***
set "pa="
set /p "pa=PA Number: "
goto:%pa%
goto:eof

:PSAT1
:PSAT2
cd biostosh\bios1.exe
goto:eof

:PXLL1
cd biostosh\bios2.exe
goto:eof


Please put your code in [code] tags for better reading.

rfdr81
Posts: 25
Joined: 26 Mar 2013 04:29

Re: Batch to run several files

#3 Post by rfdr81 » 07 Apr 2013 13:16

try your code, gives syntax error...

Endoro
Posts: 244
Joined: 27 Mar 2013 01:29
Location: Bozen

Re: Batch to run several files

#4 Post by Endoro » 07 Apr 2013 13:22

rfdr81 wrote:try your code, gives syntax error...

Yes, if you type a wrong PA number it does.

rfdr81
Posts: 25
Joined: 26 Mar 2013 04:29

Re: Batch to run several files

#5 Post by rfdr81 » 07 Apr 2013 13:27

ok, in PA number:" i put PSAT1 and press enter gives syntax error. The PSAT1 exist

:"PSAT1
:"PSAT2
cd biostosh\psat1\bios.bat
goto:eof

Endoro
Posts: 244
Joined: 27 Mar 2013 01:29
Location: Bozen

Re: Batch to run several files

#6 Post by Endoro » 07 Apr 2013 13:32

Doesn't work:

Code: Select all

:"PXLL1



Works:

Code: Select all

:PXLL1

rfdr81
Posts: 25
Joined: 26 Mar 2013 04:29

Re: Batch to run several files

#7 Post by rfdr81 » 07 Apr 2013 13:57

i put " because the smiles if i put here like this :pxll1

:PSAT1
:PSAT2
cd biostosh\psat2\bios.bat
goto:eof

here is the code:

Code: Select all

@echo off
rem *** jump to model according to PA number ***
set "pa=
set /p "pa=PA Number:
goto:%pa%
goto:eof

:PSAT1
:PSAT2
cd biostosh\psat2\bios.bat
goto:eof

:PXLL1
cd biostosh\pxll1\menu1.bat
goto:eof



but give syntax error

Endoro
Posts: 244
Joined: 27 Mar 2013 01:29
Location: Bozen

Re: Batch to run several files

#8 Post by Endoro » 07 Apr 2013 14:09

rfdr81 wrote:but give syntax error

No, error message was "path not found". It's your system, isn't it?

Code: Select all

@echo off
rem *** jump to model according to PA number ***
set "pa="
set /p "pa=PA Number: "
goto:%pa%
goto:eof

:PSAT1
:PSAT2
call biostosh\psat2\bios.bat
goto:eof

:PXLL1
call biostosh\pxll1\menu1.bat
goto:eof



Please put your code in [code] tags to avoid smiles. It's easy and free! Thanks.

rfdr81
Posts: 25
Joined: 26 Mar 2013 04:29

Re: Batch to run several files

#9 Post by rfdr81 » 07 Apr 2013 14:24

im testing with a usb emulator but the error tha gives after put the model is syntax error

Endoro
Posts: 244
Joined: 27 Mar 2013 01:29
Location: Bozen

Re: Batch to run several files

#10 Post by Endoro » 07 Apr 2013 14:36

Batch does work here. Syntax error can't belong to it. Put "pause" or "echo" commands in to see where errors come from. Check your path and file names to the other batches. Check the syntax in the called batches.

abc0502
Posts: 1007
Joined: 26 Oct 2011 22:38
Location: Egypt

Re: Batch to run several files

#11 Post by abc0502 » 07 Apr 2013 17:07

I'm not sure what is the error exactly, but why you don't use a small menu of two options ?
one for the PSAT1 and one for PXLL1 that will make it faster in choosing what you need and avoid all this troubles.

Code: Select all


@echo off
rem *** jump to model according to PA number ***
:menu
echo   === Choose PA Number ===
echo.
echo   1^> PSAT1
echo   2^> PXLL1
echo.
set "pa="
set /p "pa=PA Number: "

if /i "%pa%" == "1" Goto :PSAT1
if /i "%pa%" == "2" Goto :PXLL1
Rem here it will echo error message then clear the screen and go back to menu
echo Error ... No such Choice
ping localhost -n 2 >NUL
cls
goto :menu

:PSAT1
:PSAT2
cd /d biostosh\psat2\bios.bat
goto:eof

:PXLL1
cd /d biostosh\pxll1\menu1.bat
goto:eof

and when you use the cd command always use the switch /d as it won't work if you are trying to go to another directory that is not in the same line like:

if you are in C:\test1\Folder1
and want to change to C:\test2 it won't work as you have first to go back one level then got to the test2, the /d switch avoid that

rfdr81
Posts: 25
Joined: 26 Mar 2013 04:29

Re: Batch to run several files

#12 Post by rfdr81 » 08 Apr 2013 01:40

I can not use the option of two menus, because the all idea is to have several models with the respective bios update. In the end there is more than 100 different models so this is why im trying to do a batch file in order i put he the model i want and goes to the respective file to update the bios

abc0502
Posts: 1007
Joined: 26 Oct 2011 22:38
Location: Egypt

Re: Batch to run several files

#13 Post by abc0502 » 08 Apr 2013 01:53

i tried your original code, but replaced the cd command with ecch command to check if it do what it supposed to.
My cmd starts acting starneg and give stupid output not related to what is in the code :?: :? :!:

Edited:

happened because of the double quotes :P

And the problem was very easy :lol: , I don't know how I didn't notice :oops: :oops:

When you use the set /p you take the input and store it in the variable "pa", then the batch just continue, we didn't set the command call command not goto ( as goto will divert the flow of the batch commands but the call will just call that part of code then continue from the place it stopped )that divert the batch process to the right tag and each tag had to end with "goto :eof" in order not to got to the next tag and so on and run all one after the other.

Here Try this:

Code: Select all

@echo off
rem *** jump to model according to PA number ***
set "pa="
set /p "pa=PA Number:"
call :%pa%
pause
exit

:PSAT1
:PSAT2
cd biostosh\bios1.exe
goto :eof

:PXLL1
cd biostosh\bios2.exe
goto :eof

put all of your tags after the exit command and make sure each one ends with goto :eof

rfdr81
Posts: 25
Joined: 26 Mar 2013 04:29

Re: Batch to run several files

#14 Post by rfdr81 » 08 Apr 2013 02:44

Hello,
I tried your code, for test in the line PA, i put psat1, press enter but give the fowling error:

PA Number: psat1
Bad command or file name ":".
Press any key to continue
batch file does not contain label eof

abc0502
Posts: 1007
Joined: 26 Oct 2011 22:38
Location: Egypt

Re: Batch to run several files

#15 Post by abc0502 » 08 Apr 2013 02:51

add echo before each cd command so it show the command instead of executing it and see what happens

Post Reply