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

Author Topic: Batch File Error.  (Read 11786 times)

0 Members and 1 Guest are viewing this topic.

BlazingFire007

    Topic Starter


    Starter

    • Experience: Experienced
    • OS: Windows 8
    Batch File Error.
    « on: August 29, 2015, 05:13:46 PM »
    I am having some trouble making a batch file that writes the "&" character onto a vbs file.
    Normally i would do something like:
    @echo off
    echo Hello, how old are you?
    set /p age=
    echo What is your name?
    set /p name=
    echo You are %AGE% & your name is %name% > file.txt
    exit
    That is just an example but I want to know if either you can make cmd ignore the "&" so it doesn't try to run "your" as a command, or if there is a replacement for "&" in VBscript.

    Salmon Trout

    • Guest
    Re: Batch File Error.
    « Reply #1 on: August 30, 2015, 12:41:32 AM »
    To write certain special characters from a batch we have to prefix them with an escape character. For the ampersand (&) this is a caret (^) thus you would need to put this in your batch file

    echo You are %AGE% ^& your name is %name% > file.txt

    Table of special characters and how to escape them

    http://www.robvanderwoude.com/escapechars.php

    BlazingFire007

      Topic Starter


      Starter

      • Experience: Experienced
      • OS: Windows 8
      Re: Batch File Error.
      « Reply #2 on: August 30, 2015, 01:12:54 PM »
      Thanks, it worked!