#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2006
    Posts
    263
    Rep Power
    11

    Question Batch: argument input


    If I have a batch script call abc.bat inside C:\WINDOWS\
    from command prompt and I type > abc
    I will get the argument is ...

    I want to get the argument from DOS and print it out.. like this..
    I was wondering if I type > abc hello
    the argument is ... hello
    >abc "hello there!"
    the argument is ... hello there!

    DOS Code:
     
    echo "the argument is ..."


    thanks for the help
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Regular (2000 - 2499 posts)

    Join Date
    Mar 2006
    Posts
    2,466
    Rep Power
    1751
    It's been a long old time, but I think what you are after is %1 (for 1st parm)
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2006
    Posts
    263
    Rep Power
    11

    Wink


    Originally Posted by SimonJM
    It's been a long old time, but I think what you are after is %1 (for 1st parm)
    thx

    what about I don't how many inputs they input? The code below only print out the number, but I also want the input too..
    if i type > hello a b c d e

    I want to get a b c d e back too

    hello.bat
    BATCH Code:
     
    FOR /L %%A IN (1,1,10) DO (
    echo "-> %%A <-"
    )
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Nov 2003
    Posts
    624
    Rep Power
    34
    If you don't know how many there are, then you need to 'shift' them - it moves them all left one, and drops the first one:

    Code:
    @echo off
    rem Call me with loads of arguments
    
    :top
    echo %1
    shift
    if not "%1"=="" goto top
    (shift /? for limited help)

    Code:
    D:\>test.bat a b
    a
    b
    
    D:\>test.bat a b c d
    a
    b
    c
    d

IMN logo majestic logo threadwatch logo seochat tools logo