Computing.Net > Forums > Programming > Simple Batch Script help

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Simple Batch Script help

Reply to Message Icon

Name: MAllen
Date: May 15, 2005 at 03:11:40 Pacific
OS: Windows XP
CPU/Ram: -
Comment:

Hello.

I've just registered and wondered if you fine people could help me out on a simple batch script programme. I've never done any before and I have to write one that uses the below ideas:

Create a new batch file that will use one of the following commands:
1. net name
2. dir c:\
3. echo finished

The programme supplied will prompt the user to select one of the options from the above list. Once the selection is made the programme will run the selected command. This will be repeated until the user selects the “finish” (3rd) option.

Can any of you help me write this programme, I haven't got much time to work on it so any help would be much appreciated.

Many Thanks

Mike Allen



Sponsored Link
Ads by Google

Response Number 1
Name: Mechanix2Go
Date: May 15, 2005 at 04:08:00 Pacific
Reply:

Hio Mike,

Try this:

::==
@echo off
cls

echo 1. net name
echo 2. dir c:\
echo 3. echo finished

choice /c123 Pleasease choose

goto %errorlevel%

:1

echo here's 1
:: take out the line above and put in your command
goto :eof

:2

echo here's 2
:: take out the line above and put in your command

:3

:eof
::==

M2


If at first you don't succeed, you're about average.


0

Response Number 2
Name: Mechanix2Go
Date: May 15, 2005 at 04:15:25 Pacific
Reply:

Well...

On second thought, this is probably what you want:

::==
@echo off
cls

echo 1. net name
echo 2. dir c:\
echo 3. finished
echo.

choice /c123 Pleasease choose

goto %errorlevel%

:1

net name
goto :eof

:2

dir c:\
goto :eof

:3

echo finished

:eof
::==

M2


If at first you don't succeed, you're about average.


0

Response Number 3
Name: MAllen
Date: May 15, 2005 at 05:16:00 Pacific
Reply:

Thanks for these, I will have a go at it now and I'll get back to you.

Many Thanks again


0

Response Number 4
Name: MAllen
Date: May 18, 2005 at 02:34:18 Pacific
Reply:

Hi

I've tried both of those and nothing happens - I'm sorry but can you please run through it step by step of what to do and what to include.

Many Thanks

Mike


0

Response Number 5
Name: Mechanix2Go
Date: May 18, 2005 at 02:38:34 Pacific
Reply:

Mike,

"nothing happens"

No error, no output?

M2


If at first you don't succeed, you're about average.


0

Related Posts

See More



Response Number 6
Name: MAllen
Date: May 18, 2005 at 08:05:08 Pacific
Reply:

Hi

No Error Message or Output at all I just double click the program and it just ends.


0

Response Number 7
Name: Mechanix2Go
Date: May 18, 2005 at 23:58:30 Pacific
Reply:

Go to a command prompy and run it.

M2


If at first you don't succeed, you're about average.


0

Response Number 8
Name: MAllen
Date: May 19, 2005 at 08:33:30 Pacific
Reply:

When I wrote the script out in Notepad and then saved it, should I leave the default as .txt or add exe at the end as others have done that.

And then they just double click on the exe file and it runs.


0

Response Number 9
Name: Mechanix2Go
Date: May 19, 2005 at 21:56:54 Pacific
Reply:

Hi Mike,

In order for a batch file to work, it needs to be named blabla.BAT, like:

Mikes.BAT

123.BAT

etc

M2


If at first you don't succeed, you're about average.


0

Response Number 10
Name: MAllen
Date: May 20, 2005 at 06:32:34 Pacific
Reply:

Hi

I've done that and copied your code from the second example and again it runs and then straight away ends.


0

Response Number 11
Name: Mechanix2Go
Date: May 20, 2005 at 06:56:33 Pacific
Reply:

Hi Mike,

What is on the screen after it runs?

M2


If at first you don't succeed, you're about average.


0

Response Number 12
Name: MAllen
Date: May 20, 2005 at 08:35:57 Pacific
Reply:

Hi

Nothing - it appears then disappears in a second so I can't see what is on the screen :-(

Mike


0

Response Number 13
Name: Mechanix2Go
Date: May 20, 2005 at 08:50:13 Pacific
Reply:

OK,

What's on the screen before you run it?

M2


If at first you don't succeed, you're about average.


0

Response Number 14
Name: MAllen
Date: May 20, 2005 at 09:41:52 Pacific
Reply:

In the folder it's saved it just the name of the file and reads ms dos batch file

and when I click on it it appears and within a second disappears and I don't have time to read what is on it.


0

Response Number 15
Name: Mechanix2Go
Date: May 20, 2005 at 09:47:27 Pacific
Reply:

#7

M2


If at first you don't succeed, you're about average.


0

Response Number 16
Name: MAllen
Date: May 21, 2005 at 05:26:27 Pacific
Reply:

Hi

What does #7 do?


0

Response Number 17
Name: The Assistant
Date: May 21, 2005 at 13:05:49 Pacific
Reply:

To get it to work on my system I had to include the path to the Choice command. I also inserted a couple of Pauses to allow you to verify the successdful completion.

@echo off
cls
echo 1. net name
echo 2. dir c:\
echo 3. finished
echo.
c:\windows\command\choice /c123 Please choose
goto %errorlevel%
:1
net name
goto :eof
:2
dir c:\
Pause
goto :eof
:3
echo finished
Pause
:eof


0

Response Number 18
Name: MAllen
Date: May 22, 2005 at 06:04:10 Pacific
Reply:

Hi

So if I copy and paste this into notepad and save it as a batch file it should work succesfully?

Thanks for this again and for being very patient with me.

Mike


0

Response Number 19
Name: Mechanix2Go
Date: May 22, 2005 at 06:54:42 Pacific
Reply:

Hi Mike,

#7 refers you to reply 7 where I said you need to go to a command prompt.

That's the only way to get it working right.

M2


If at first you don't succeed, you're about average.


0

Response Number 20
Name: The Assistant
Date: May 22, 2005 at 11:21:08 Pacific
Reply:

Copy it into Word Pad and not Note Pad. Then select "Save As".

Make the File Name any name you want but the extenstion must be ".bat"

Change the Save AS Type to "Text Document-MS DOS Format"

Save the file and then go to the location you saved it and double click on it to execute.


0

Response Number 21
Name: Mechanix2Go
Date: May 22, 2005 at 11:33:25 Pacific
Reply:

Hi The,

He's been clicking on it for a few days. That's the problem. Not the solution.

Difficult to figure what advantage wordpad might bring to this saga. 21 and counting.

M2


If at first you don't succeed, you're about average.


0

Response Number 22
Name: The Assistant
Date: May 22, 2005 at 20:40:02 Pacific
Reply:

The copy and paste option eliminates typos. Without the path to the choice command the batch file just flashes on the screen for a split second and aborts without any error or indication why.

Using NotePad won't work because it doesn't offer the option of saving the file in a "Document Text-MS DOS Format" whereas Word Pad does.


0

Response Number 23
Name: Mechanix2Go
Date: May 22, 2005 at 23:35:13 Pacific
Reply:

Hi The,

Interesting point about WP / NP.

Seems many, many folks have used NPt for the "text editor" of choice for a long time.

Windows also has "EDIT", FWIW; I never use it.

I use a real DOS text editor.

You're correct in guessing that CHOICE may not be in the path. Hard tellin' where it might be.

But if CHOICE is not in the path, you'll get an error.

That's why I'm trying to get Mike to run it from a prompt.

M2


If at first you don't succeed, you're about average.


0

Response Number 24
Name: MAllen
Date: May 23, 2005 at 00:24:38 Pacific
Reply:

I typed it out in wordpad and saved it as a text document-MS Dos format.

I double click on the file and it opens but under the options it reads:

"The System cannot find the path specified
finished
press any key to continue.."

When I type in 1 or 2 or 3 it just ends!

:-(

Thanks for the help again on this batch file - I have two weeks to make sure it runs succesfully :-)


0

Response Number 25
Name: The Assistant
Date: May 23, 2005 at 08:01:05 Pacific
Reply:

Do a search for "choice" on your system and note the path to it when found. Modify the instructions in the Bat file with the path you found.


0

Response Number 26
Name: michaliv
Date: June 1, 2005 at 05:56:21 Pacific
Reply:

If you have Win 2k or XP you may have to use the set command:

@ECHO off
cls
:start
ECHO.
ECHO 1. net name
ECHO 2. dir c:\
ECHO 3. Finish
set choice=
set /p choice=Type the number to print text.
if not '%choice%'=='' set choice=%choice:~0,1%
if '%choice%'=='1' goto 1
if '%choice%'=='2' goto 2
if '%choice%'=='3' goto 3
ECHO "%choice%" is not valid please try again
ECHO.
goto start
:1
net name
goto start
:2
dir c:
goto start
:3
goto end
:end
ECHO Program Closed.


0

Response Number 27
Name: Mechanix2Go
Date: June 1, 2005 at 22:21:10 Pacific
Reply:

In NT choice sets errlevel.



0

Sponsored Link
Ads by Google
Reply to Message Icon






Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: Simple Batch Script help

Help with simple batch scripting www.computing.net/answers/programming/help-with-simple-batch-scripting/15226.html

Batch Script Help Needed www.computing.net/answers/programming/batch-script-help-needed/14475.html

Batch Script Help and Suggestions www.computing.net/answers/programming/batch-script-help-and-suggestions/14552.html