Welcome to The Tech 
Guide
Google
 
Web www.thetechguide.com
Geeks with attitude
Navigation
  • Home
  • How-To's
  • Tweaks
  • Hardware
  • Software
  • Games
  • Our Picks
  • Downloads
  • FAQ's
  • Forum
  • Chat
  • Tech Deals
  • Links
  • Email

  • Site News
    Our Black Friday section is now online! Click here to check it out.

    Active Discussions
    [an error occurred while processing this directive]


      

    Tutorial on Basic Windows 2000 DOS

      This Section Will Cover
    • 00. What a file is under win enviroment
    • 01. What a variable is in %win2k% batch and how to create them.
    • 02. What echo echo. @echo off does.
    • 03. What operators like > and >> and | do.
    • 04. What a ::comment is.
    • 05. What & does and how to use it &::creatively.
    • 06. What 'DIR' and 'SORT' is and does
    • 07. What a * and a ? mean to the DOS shell.
    • 08. What GOTO _is when used with :_labels, also using PING to create a delay.
    • 09. What if "statements"=="are and what they do".
    • 10. What a basic "for" loop is/does.
    • 11. How to use low interger values with variables.
    • 12. How to parse strings into substrings.
    • 13. How to echo non-echoable characters.
    • 14. How to pass %arguments to a .bat file.
    • 15. Summary

    First to echo a % you do %%. You have to put 2 of them. echo %% would only echo 1 %, the reason goes back to variables.

    Ok, you must know that there are certain characters you cannot echo out. Remember DIR /B | FIND ".bat", well you cannot echo out a pipe | character normally. This is a character that the DOS shell (cmd.exe or command.com) uses for operations.

    Some of these characters are |, >, <, & as well as several more. You might run across certain characters like these that you will want to echo out.

    There might be an easier way of doing what I'm about to show you, however I stumbled across this on accident and just kept using it since I already knew it worked. However, it's a long approach to accomplish something simple.

    First try to do this...but it won't work
    @echo off
    echo.
    echo This is 1 %% sign
    echo.
    echo This is a pipe character in a file | >> "some_file.txt"
    pause >nul
    The above will NOT work.

    Ok, the way I stumbled across is to use these non-echoable characters in complete memory more or less. I'm not sure why this works exactly, but it just does.
    @echo off
    echo.
    echo This is 1 %% sign
    echo.
    FOR /F "tokens=*" %%i IN ("This is a pipe character in a file |") DO ECHO %%i>> "some_file.txt"
    START notepad some_file.txt
    echo  Press [ENTER] to exit
    pause>nul
    or
    @echo off
    echo.
    echo This is 1 %% sign
    echo.
    FOR /F "tokens=*" %%i IN ("|") DO ECHO This is a pipe character in a file %%i>> "some_file.txt"
    START notepad some_file.txt
    echo  Press [ENTER] to exit
    pause>nul
    I don't know why this works. My best guess is that it enters memory as text, and exits memory as text. That is my best guess. Remember in a FOR loop when you want to put text inside the ( ) you use double qoutes "'s. If you use usebackq you use single qoutes ''s instead of double qoutes.

    Try this one too....
    @echo off
    echo.
    FOR /F "tokens=*" %%i IN ("| > < &") DO ECHO These are some of the non-echoable characters echoed %%i>> "some_file.txt"
    START notepad some_file.txt
    It works, so if you ever need to echo these characters, this is one possibility. As I said there might be an easier way to do this, but this is what I used because it's what I knew worked. There is a catch to this though. Sometimes you will have to put certain characters outside the ("") to get them to echo. One of these situations might be if you want to put an entire for loop inside the ( ) as text. It's really trial and error, but for almost all situations the solution I presented works so always try it first/last to try to solve this problem of echoing out non-echoable characters.

    Also you see another command named START. The START command starts a file via windows. It starts it just like if you were to double click it. In the example above, the dos shell that executes the script, immediately closes after START. To keep the shell open, you sould use the /W switch with START. Doing START /W notepad some_file.txt would keep the shell open until you closed the process of notepad that it started. START /W notepad some_file.txt is the same thing as not putting START at the begining, like notepad some_file.txt You could run notepad this way but it would be the same thing as START /W. So you might as well use START with or without the /W switch just to get in the habbit if you're going to be starting a lot of things from your scripts. You would have to wait for the process of notepad to close before the shell script window would close using either method of START /W notepad some_file.txt or notepad some_file.txt.


    Click here to continue





    Questions? Ask in the forum or email me.

    For the Privacy Policy, click here.
      
    Past Articles
  • Build your own Apple Clone
  • AllofMP3 Review
  • Tutorial to Basic Windows 2000 DOS
  • Extracting and joining MPG2 files from SVCD
  • Modifying your Windows XP Boot Logo
  • Unlocking WinXP's setupp.ini
  • Making a Full Screen Bios Logo
  • Making your WinMe CD bootable
  • Auto-insert your Win9x serial
  • Auto-insert your Office2kserial
  • Why FedEx Sucks