views:

51

answers:

2

Im currently trying to execute a batch script under dos thats being booted before windows

Im trying to Load the img file containing the boot sectors to boot into a "bootable floppy" from flash disk and execute a batch file called installer.bat

When the batch file is run it should ask a the technician to verify a drive letter, and then the batch script will copy over a folder called xosl to that particular hard drive, i.e. C:\xosl\

This is what I have so far:

echo OFF
CLS
:MENU
echo .
echo ...............................................
echo                 XOSL Installer
echo ...............................................
echo .

SET /P D=Enter drive letter such as (C:):

IF NOT EXIST %D% GOTO NOWINDIR
   mkdir %D%/xosl/
   xcopy /xosl/*.* %D%/xosl/
   cd %D%/xosl/
   START %D%/xosl/install.exe 
:NOWINDIR
   ECHO Drive does not exists
   GOTO MENU

The issue is it keeps iterating over and over again, this is why i think im going wrong within the SET /P... what am i doing wrong ?


Update:

This is what im getting..

...............................................
                XOSL Installer
...............................................

Unable to create directory
Invalid directory
Invalid directory
Syntax Error
A:\>

And its not asking me to set a Directory?

+1  A: 

Indentation has no effect so after START %D%/xosl/install.exe it'll continue at :NOWINDIR.

You may want to do that:

echo OFF
CLS
:MENU
echo .
echo ...............................................
echo                 XOSL Installer
echo ...............................................
echo .

SET /P D=Enter drive letter such as (C:):

IF EXIST %D% (
   mkdir %D%/xosl/
   xcopy /xosl/*.* %D%/xosl/
   cd %D%/xosl/
   START %D%/xosl/install.exe 
) ELSE (
   ECHO Drive does not exists
   GOTO MENU
)

PS: Try to add quotes around each variable like that "%D%". You may get only the first letter using this "%D:~0,1%:".

Wernight
Just recompiling the IMG to test.
RobertPitt
i dont think the `SET /P D=Enter drive letter such as (C:):` is working, im in DOS not windows, would this have an effect ?
RobertPitt
`SET /P` is available in modern DOS. You may want to try `CHOICE` or if that fails also some hard hack, or download an EXE that does the same thing. PS: If you have an old old DOS, my brackets wont work. You should use the GOTO method as described in Andrew's post. You can use `goto :eof` without defining "eof" label though.
Wernight
The dos I have just compiled from a Windows XP SP2 installation. I can get the latest version of a WIN 7 machine and give that a go.
RobertPitt
Windows XP SP2 MSDOS has `SET /P`. How are you running it?
Wernight
Im loading Grub4Dos via USB, then i have a command that puts the `.img` into the Memory via Map but still under a floppy drive, and then i run the `install.bat` via prompt.
RobertPitt
SET command does work because within prompt i type: `A:/>SET H=1` and the command executes with no errors :/
RobertPitt
Grub4Dos should not be MSDOS. Do you have the `choice` command? You may try using Linux commands like `read -p "Install XXX (y/n)?`. If that doesn't work, you may have to change your DOS, download a third party tool, or change scripting language.
Wernight
You may find more on http://www.techreplies.com/ms-dos-65/mask-user-input-without-third-party-517628/
Wernight
Grub4Dos just executes me into the image file and boots the dos, when im in prompt, Grub4Dos has gone, I think the issue was that when you create a bootable floppy from XP its actually ME version.
RobertPitt
What about the other suggestions I gave you, like [getvar](http://internet.cybermesa.com/~bstewart/getkv.html)?
Wernight
what happens if you type `choice` at the command prompt? do you get `[Y,N]?` - if so, as @Wernight suggested, `choice` is the way to go
Andrew
Yes by default. You can extend it to include all letters and exclude the choices. Like that: `CHOICE /C:ABCDEFGHIJKLMNOPQRSTUVW /N "Drive letter?"`. The `%errorlevel%` will give you the selected option. PS: Consider voting up my comments if they help, esp. it's more another question. :p
Wernight
Yea i traced the issue down to the modifier, when i use the command `SET` on its own to print out ENV_VARS it shows the value of `D` to be */P D=C:\xosl\\* where the modifier is becoming part of the value and there for there is no *pause*
RobertPitt
A: 

You just need a way to jump to the end of the batch file when it works, as it's just running through and executing the :NOWINDIR code as well - try adding the following:

IF NOT EXIST %D% GOTO NOWINDIR
   mkdir %D%/xosl/
   xcopy /xosl/*.* %D%/xosl/
   cd %D%/xosl/
   START %D%/xosl/install.exe
   GOTO END
:NOWINDIR
   ECHO Drive does not exists
   GOTO MENU
:END


also, echo. (no space between the echo and the .) will give you a blank line

Andrew
Updated my question, theres and issue with the `SET /p`
RobertPitt
Can you try it without a prompt string? i.e. `SET /P D=`
Andrew
Have you tried typing `CHOICE` at your DOS command prompt to see if `CHOICE` is available as an alternative to `SET /P` (as per the question in one of @Wernight's comments?
Andrew