Batch script ignores the parameters

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
yaniv_it
Posts: 2
Joined: 09 May 2012 07:05

Batch script ignores the parameters

#1 Post by yaniv_it » 09 May 2012 07:21

Hi,

I wrote a batch script which receives 9 parameters and insert them in a file.
The problem is if the parameters are in size of 1 character the are been ignored, if their size is greated it's ok.
This is the script:

echo off
set PROCESS_NUMBER=%1
set RUN_NUMBER=%2
set LEVEL_NUMBER=%3
set PARAM_NAME_1=%4
set PARAM_VALUE_1=%5
set PARAM_NAME_2=%6
set PARAM_VALUE_2=%7
set PARAM_NAME_3=%8
set PARAM_VALUE_3=%9


type NUL>PARAM_FILE_%PROCESS_NUMBER%.txt

set PARAM_FILE=PARAM_FILE_%PROCESS_NUMBER%.txt

echo $$PROCESS_NUMBER=%PROCESS_NUMBER%>>%PARAM_FILE%
echo $$RUN_NUMBER=%RUN_NUMBER%>>%PARAM_FILE%
echo $$%PARAM_NAME_1%=%PARAM_VALUE_1%>>%PARAM_FILE%
echo $$%PARAM_NAME_2%=%PARAM_VALUE_2%>>%PARAM_FILE%
echo $$%PARAM_NAME_3%=%PARAM_VALUE_3%>>%PARAM_FILE%
echo $$LEVEL_NUMBER=%LEVEL_NUMBER%>>%PARAM_FILE%

if I'm running like this C:\>k.bat 999 2 3 4 5 6 7 8 9
than this is output of the file

C:\>type PARAM_FILE_999.txt
$$PROCESS_NUMBER=999

if I'm running like this C:\>k.bat 999 20 30 40 50 60 70 80 90
than this is output:

C:\>type PARAM_FILE
$$PROCESS_NUMBER=999
$$RUN_NUMBER=20
$$40=50
$$60=70
$$80=90
$$LEVEL_NUMBER=30

Help someone? thanks.

Squashman
Expert
Posts: 4488
Joined: 23 Dec 2011 13:59

Re: Batch script ignores the parameters

#2 Post by Squashman » 09 May 2012 07:49

Change the redirection to this.

>>%PARAM_FILE% echo $$PROCESS_NUMBER=%PROCESS_NUMBER%
>>%PARAM_FILE% echo $$RUN_NUMBER=%RUN_NUMBER%
>>%PARAM_FILE% echo $$%PARAM_NAME_1%=%PARAM_VALUE_1%
>>%PARAM_FILE% echo $$%PARAM_NAME_2%=%PARAM_VALUE_2%
>>%PARAM_FILE% echo $$%PARAM_NAME_3%=%PARAM_VALUE_3%
>>%PARAM_FILE% echo $$LEVEL_NUMBER=%LEVEL_NUMBER%

jeb
Expert
Posts: 1058
Joined: 30 Aug 2007 08:05
Location: Germany, Bochum

Re: Batch script ignores the parameters

#3 Post by jeb » 09 May 2012 08:08

Or try this

Code: Select all

(
  echo $$PROCESS_NUMBER=%PROCESS_NUMBER%
  echo $$RUN_NUMBER=%RUN_NUMBER%
  echo $$%PARAM_NAME_1%=%PARAM_VALUE_1%
  echo $$%PARAM_NAME_2%=%PARAM_VALUE_2%
  echo $$%PARAM_NAME_3%=%PARAM_VALUE_3%
  echo $$LEVEL_NUMBER=%LEVEL_NUMBER%
) >%PARAM_FILE%

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: Batch script ignores the parameters

#4 Post by foxidrive » 09 May 2012 18:06

The reason is that in NT class windows you cannot have some numerals before a redirection sign.

This will fail because the 1 is interpreted as redirecting a stream number (STDOUT).

echo 1>file.txt

yaniv_it
Posts: 2
Joined: 09 May 2012 07:05

Re: Batch script ignores the parameters

#5 Post by yaniv_it » 10 May 2012 00:29

Thanks fellows it's working !!! :D

>>%PARAM_FILE% echo $$PROCESS_NUMBER=%PROCESS_NUMBER%

Post Reply