Welcome guest. Before posting on our computer help forum, you must register. Click here it's easy and free.

Author Topic: Batch file help: Creating batch files with notepad  (Read 5018 times)

0 Members and 1 Guest are viewing this topic.

alice8

    Topic Starter


    Starter

    • Experience: Beginner
    • OS: Windows Vista
    Batch file help: Creating batch files with notepad
    « on: October 22, 2013, 04:50:43 PM »
    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.

    DaveLembke



      Sage
    • Thanked: 662
    • Certifications: List
    • Computer: Specs
    • Experience: Expert
    • OS: Windows 10
    Re: Batch file help: Creating batch files with notepad
    « Reply #1 on: October 22, 2013, 06:54:47 PM »
    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.

    patio

    • Moderator


    • Genius
    • Maud' Dib
    • Thanked: 1769
      • Yes
    • Experience: Beginner
    • OS: Windows 7
    Re: Batch file help: Creating batch files with notepad
    « Reply #2 on: October 22, 2013, 07:06:46 PM »
    Hee...good call.
    " Anyone who goes to a psychiatrist should have his head examined. "

    alice8

      Topic Starter


      Starter

      • Experience: Beginner
      • OS: Windows Vista
      Re: Batch file help: Creating batch files with notepad
      « Reply #3 on: October 22, 2013, 10:49:39 PM »
      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.



      foxidrive



        Specialist
      • Thanked: 268
      • Experience: Experienced
      • OS: Windows 8
      Re: Batch file help: Creating batch files with notepad
      « Reply #4 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.

      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 :EOF

      kyle_engineer



        Intermediate
      • 010010110101100
      • Thanked: 4
        • Yes
      • Certifications: List
      • Computer: Specs
      • Experience: Expert
      • OS: Windows 7
      Re: Batch file help: Creating batch files with notepad
      « Reply #5 on: October 23, 2013, 02:37:35 PM »
      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:
      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. :P

      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. :)
      "Any answer is only as good as it satisfies the question." - Me

      0000000100101011000 -
      010010010010000001001100010011110100110 001000000010110010100111101010101

      alice8

        Topic Starter


        Starter

        • Experience: Beginner
        • OS: Windows Vista
        Re: Batch file help: Creating batch files with notepad
        « Reply #6 on: October 23, 2013, 10:29:45 PM »
        Thanks foxidrive, this is very helpful! And kyle_engineer I will make sure its a more basic script, thanks!

        Troncc



          Rookie

          Thanked: 2
          • Yes
        • Computer: Specs
        • Experience: Guru
        • OS: Windows XP
        Re: Batch file help: Creating batch files with notepad
        « Reply #7 on: October 28, 2013, 12:02:58 PM »
        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. ;D
        If at first you don't succeed, try it 1000 other ways..