Computing.Net > Forums > Disk Operating System > DOS command line arguments

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

DOS command line arguments

Reply to Message Icon

Name: StephenJ
Date: July 27, 2009 at 07:34:58 Pacific
OS: Windows XP
Subcategory: General
Comment:

Hi, how can I get all the DOS command line arguments in a single variable?

If I were pass the args as:
temp.bat a b c d e f,

I want the assign all the args as a sentence in a single variable.
e.g var1="a b c d e f"



Sponsored Link
Ads by Google

Response Number 1
Name: Mechanix2Go
Date: July 27, 2009 at 07:42:25 Pacific
Reply:

set var=%1 %2 %3 %4 %5 %6


=====================================
If at first you don't succeed, you're about average.

M2


0

Response Number 2
Name: StephenJ
Date: July 27, 2009 at 09:07:49 Pacific
Reply:

I am sorry, I did not make it clear earlier that the number of arguments may not be the same every time. It could be 6 or 5 or 4. Is there a common variable that holds all the args similar to $? in Unix.


0

Response Number 3
Name: Mechanix2Go
Date: July 27, 2009 at 09:14:01 Pacific
Reply:

I don't think so, but this:

set var=%1 %2 %3 %4 %5 %6

will work if there is no %5 %6 etc.


=====================================
If at first you don't succeed, you're about average.

M2


0

Response Number 4
Name: IVO
Date: July 28, 2009 at 03:00:29 Pacific
Reply:

Here you are in the real plain DOS Forum, i.e. the legacy MS (and its clones) operating system.

Under that environment (up to Windows ME) you have to code

  set var=
:LOOP
  if "%1"=="" goto :DONE
  set var=%var% %1
  shift
  goto :LOOP
:DONE
  echo. VAR=%var%

However under NT kernel systems as Windows 2K/XP/Vista where the command interpreter is cmd.exe instead of command.com you can code

set var=%*

to catch the whole command tail by one shot.

0

Response Number 5
Name: StephenJ
Date: July 28, 2009 at 06:52:49 Pacific
Reply:

IVO, this was exactly what I was looking for. Thank you very much.


0

Related Posts

See More



Response Number 6
Name: carlsomo
Date: August 16, 2009 at 20:06:52 Pacific
Reply:

Try using %*
That represents all command line args except %0


0

Response Number 7
Name: StephenJ
Date: August 17, 2009 at 06:39:26 Pacific
Reply:

Hi Carlsomo, Thank you.


0

Sponsored Link
Ads by Google
Reply to Message Icon





Use following form to reply to current message:

Login or Register to Reply
LoginRegister


Sponsored links

Ads by Google


Results for: DOS command line arguments

DOS command line help needed www.computing.net/answers/dos/dos-command-line-help-needed/14756.html

max length of dos command line www.computing.net/answers/dos/max-length-of-dos-command-line/2281.html

DOS Command Line Length www.computing.net/answers/dos/dos-command-line-length/4056.html