Page 1 of 2

Batch to run several files

Posted: 07 Apr 2013 12:50
by rfdr81
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

Re: Batch to run several files

Posted: 07 Apr 2013 13:05
by Endoro
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.

Re: Batch to run several files

Posted: 07 Apr 2013 13:16
by rfdr81
try your code, gives syntax error...

Re: Batch to run several files

Posted: 07 Apr 2013 13:22
by Endoro
rfdr81 wrote:try your code, gives syntax error...

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

Re: Batch to run several files

Posted: 07 Apr 2013 13:27
by rfdr81
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

Re: Batch to run several files

Posted: 07 Apr 2013 13:32
by Endoro
Doesn't work:

Code: Select all

:"PXLL1



Works:

Code: Select all

:PXLL1

Re: Batch to run several files

Posted: 07 Apr 2013 13:57
by rfdr81
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

Re: Batch to run several files

Posted: 07 Apr 2013 14:09
by Endoro
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.

Re: Batch to run several files

Posted: 07 Apr 2013 14:24
by rfdr81
im testing with a usb emulator but the error tha gives after put the model is syntax error

Re: Batch to run several files

Posted: 07 Apr 2013 14:36
by Endoro
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.

Re: Batch to run several files

Posted: 07 Apr 2013 17:07
by abc0502
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

Re: Batch to run several files

Posted: 08 Apr 2013 01:40
by rfdr81
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

Re: Batch to run several files

Posted: 08 Apr 2013 01:53
by abc0502
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

Re: Batch to run several files

Posted: 08 Apr 2013 02:44
by rfdr81
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

Re: Batch to run several files

Posted: 08 Apr 2013 02:51
by abc0502
add echo before each cd command so it show the command instead of executing it and see what happens