PDA

View Full Version : batch file



Jiggy
10-25-2003, 01:28 PM
I want to wright a simple batch file just to see how they are put together and work, just something that will work from floppy, cd just to play with.

Can anyone help me out with whats needed.

Thanks.

jeeza
10-25-2003, 04:21 PM
Open notepad.
Write :

@echo off
echo "Hello World!"
end

and save as "Helloworld.bat".
(the extension for batch files is .bat.)
I don't know if it's totally correct, but it should write "Hello World!" to your dosprompt screen.
Why don't you just look on the Web with google ?

tommy
10-26-2003, 02:51 AM
It is likely you already have some BAT files on your computer, so, do a search/find for *.bat and take a look at some of them with wordpad or similar editor.

sleddog
10-26-2003, 09:34 AM
Batch files can be made interactive by using CHOICE. This requires CHOICE.COM, a tiny DOS app that comes with Windows 95/98, but is not included in Windows 2000/XP. In that case you could copy it from a Windows 98 system to your C:\Winnt directory. That isn't strictly legal but I doubt if Mr. Gates would be too upset :)

Here's a sample batch file illustrating how to make an interactive batch file using Choice:



@echo off

echo Choose an Option
echo ----------------
echo.
echo 1. Tell a lie
echo 2. Tell the truth
echo.
choice /C:12 Your choice:
if errorlevel 2 goto TRUTH
if errorlevel 1 goto LIE

:TRUTH
echo.
echo The sky is blue!
echo.
pause
exit

:LIE
echo.
echo The sky is green!
echo.
pause
exit

Jiggy
10-26-2003, 09:55 AM
Thanks sleddog,

How do i run it and from were?

Why i ask is im making and unattended xpcd with SP1, drivers, app and the like and i wanted to try wrighting a small .bat as a starter.

So if i copy/paste your .bat to notepad save as filename.bat that be ok?