• وبلاگ : پاي سيب
  • يادداشت : Cellular automaton
  • نظرات : 0 خصوصي ، 80 عمومي
  • تسبیح دیجیتال

    نام:
    ايميل:
    سايت:
       
    متن پيام :
    حداکثر 2000 حرف
    كد امنيتي:
      
      
     
    + DOS 

    Batch File Parameters

    You may put and use command-line parameters into your batch-files.

    Suppose you had a batchfile called "test.bat" and these were the contents:

    @echo off
    if (%1) == (Hi) echo %1

    and at the command line you entered: test.bat Hi, the output would be "Hi". If you entered test.bat bye you would get no response because the parameter did not match. the "%1" refers to the first parameter on the command line after the batch file name. If you want to two parameters, the would look like this:

    @echo off
    if (%1) == (Hi) echo %1 %2

    You could also just spit out what someone types in without a condition:

    @echo off
    echo %1 %2 %3 %4 %5 %6

    Then typing test.bat dont tell me what to do would produce
    dont tell me what to do because it is set up to handle 6 parameters and there are six words. You can tease someone by changing the order:

    @echo off
    echo %6 %3 %1 %2 %5 %4

    do me dont tell to what

    Making your own variables
    You may use the SET command to create your own internal paramaters. This batch file:

    @echo off
    set myvar=Hi Joe
    echo %myvar% is myvar

    Will print Hi Joe is myvar. Notice a few important points. when we initialize myvar there are no % around it. When we use it, it must be between two %. Also, there must be no spaces between the = and the terms. When myvar is not in a set command or between % it is treated as a literal string.

    You can make up your own parameter names and have many of them:

    @echo off
    set name=John Smith
    set address=1 main street
    set city=helltown

    echo %name%
    echo %address%
    echo %city%