1.

Solve : Batch file help: Creating batch files with notepad?

Answer»

I need help creating this batch file in notepad, and I am not getting the correct results. I hope someone can help me and point me in the right direction.

Create the following batch file. These batch files should do the actions indicated. None of these files should echo any of their commands to the console. Include appropriate comment lines that state what the file will do.

1. Create a batch file that changes the command prompt based on the user’s parameter:
a) The batch file will run with a single parameter that represents one of three prompt choices.
b) Compare the parameter to each of its possible values. If there is a match: Go to a different label where a new prompt will be set. Allow for one instance where the prompt is restored to its original setting. Include at least one special code in each of them. Go to a label at the end of the file and quit.
Is this homework?

If so most of the ways to achieve this will be in the book that your studying. I feel that if we gave you a pointer on how to do it, we would be giving away the answers.

Can you share code example of what you have now and we can point out corrections maybe? I dont like to do peoples homework for them, but I dont mind pointing out corrections to be made.... I guess I am saying that I am willing to help, but not do all the work for you.

*Also a common mistake I have seen with using notepad when creating batch files is that the batch file is saved as a text file because notepad saves to .txt by default, so you will want your batch files to have the .bat file extension. Just wanted to mention in case you didnt know this. Other mistakes are in naming the batch file a similar name to that of an already existing program or command, so its best to name it something like test1.bat or homework1.bat to avoid naming conflicts.Hee...good call.This is part of a lab assignment yes. We don't have a text book, all the professor does is he gives us a couple of notes and then gives this lab. When this is your first time every using DOS you have no idea what the *censored* you are doing, its like a totally new language I'm expected to know how to speak. I have tried asking him for help but all he does is tells me the ANSWER and I never end up understanding how to do it. I have tried to figure it out. For part a) I'm just not quite sure what its asking. I guess what would be helpful is if I could come to UNDERSTAND batch files. I don't expect you to tell me the answers but to give me more of an understanding. I know how to save the file to make it a batch file. I'm just confused where it says in the question about the parameter representing one of three prompt choices. I learned that prompt -is what gets displayed in the terminal when you want to enter something; it's part of some initial configurations. h:\>prompt Hey! Result: Hey! I just don't understand what the question means. I'm really sorry if I'm not making sense its just this stuff is so over my head its hard to wrap my mind around it.
So, for a) would I go:

@echo off
rem Create a batch file that will use a single parameter to represent one of three prompt choices and compare the parameter to its values.
:loop -no idea what this is for he didn't really explain it.
echo Hello %1
not sure what to do for the other three prompt choices that need to be here. would it be using a label like with a COLON eg. :prompt1? oh and would i need to use goto?

I'm pretty sure I'm way off, so if you can't explain it without giving the answers thats okay I'll try to figure it out on my own. Thanks though.


Here's a framework for you to run and examine. Hopefully you can follow it and change it to suit you.

It starts a new session of cmd so that the prompt changes can be seen.

Code: [Select]@echo off
if "%~1"=="" (
echo enter an argument at the command line
pause
goto :EOF
)

if /i "%~1"=="A" goto :labelA
if /i "%~1"=="B" goto :labelB
if /i "%~1"=="C" goto :labelC
goto :EOF

:labelA
prompt letter A - $P$G
cmd /k echo Type EXIT to quit
goto :EOF

:labelB
prompt letter B - $P$G
cmd /k echo Type EXIT to quit
goto :EOF

:labelC
prompt $P$G
cmd /k echo Type EXIT to quit
goto :EOFQuote from: foxidrive on October 23, 2013, 03:04:10 AM

Here's a framework for you to run and examine. Hopefully you can follow it and change it to suit you.

It starts a new session of cmd so that the prompt changes can be seen.


That's a pretty simple way of doing what you want... but remember that if this is for an intro class, using foxi's exact script will get you busted. That doesn't look like a beginner's script.

If you can understand that, then you'll know what the teacher/prof is expecting of you and you'll be able to WRITE your own (more basic) script.

Also, you said:
Quote from: alice8 on October 22, 2013, 04:50:43 PM
None of these files should echo any of their commands to the console.

was one of the requirements. If that's the case, you'll just need to modify a few things that foxi put... I'll let you figure out what things. Run foxi's script if you need to to see what actually echoes to the console.

Last thing - if you don't have to use notepad.exe I'd personally recommend Notepad++. It's FREE and has syntax highlighting as well as language presets. Makes things a lot easier for me personally. Thanks foxidrive, this is very helpful! And kyle_engineer I will make sure its a more basic script, thanks! If you get into programming .bat files heavily, you might want to use this program:

http://www.contexteditor.org/

It has the syntax highlighting & language presets, plus you can also program a button to testrun your batch file.
I use it to 'save and run' in one click.

After every major change I make in my .bat file, I click the button to run it. Saves a lot of time.


Discussion

No Comment Found