|
|
|
#1 (permalink) |
|
Messages: n/a
Hébergeur: |
Hello!,
I'm trying to obtain a random number in batch file. if I type > set /a X=%random%%108 in command prompt work ok, but if I put this instruction in batch file, don't work! anybody know why? thanks! -- Message posted via http://www.winserverkb.com |
|
|
|
#2 (permalink) |
|
Messages: n/a
Hébergeur: |
"bvb47 via WinServerKB.com" <u37442@uwe> wrote in message
news:797b38778d19c@uwe... > Hello!, > > I'm trying to obtain a random number in batch file. > > if I type > > set /a X=%random%%108 > in command prompt work ok, but if I put this instruction in batch file, don't > work! > > anybody know why? Try doubling the use of %: http://www.aumha.org/a/batches.php "NOTE: The %% is necessary because this is in a batch file which, otherwise, would give a special meaning to a single %. " |
|
|
|
#3 (permalink) |
|
Messages: n/a
Hébergeur: |
"bvb47 via WinServerKB.com" <u37442@uwe> wrote in message news:797b38778d19c@uwe... > Hello!, > > I'm trying to obtain a random number in batch file. > > if I type >> set /a X=%random%%108 > in command prompt work ok, but if I put this instruction in batch file, > don't > work! > > anybody know why? > > thanks! > > -- > Message posted via http://www.winserverkb.com > At a command prompt I get: nnnnn%108 where nnnnn is a random integer. In a batch file I get: nnnnnn08 This is because %1 is blank. If I pass "Test" to the batch file as the first argument, I get an error because "Test" is not numeric. If I pass 23 as the argument, I get: nnnnnn2308 Seems to work for me. Of course the environment variable only lasts until I exit the command prompt. -- Richard Mueller Microsoft MVP Scripting and ADSI Hilltop Lab - http://www.rlmueller.net -- |
|
|
|
#4 (permalink) |
|
Messages: n/a
Hébergeur: |
the solution is written by BSOD in nabble forum:
---------------- BSOD wrote: Cos in a batch %108 is interpreted as a command line parameter passed to the . bat, the same as %0 and %1 etc etc. use this : SET /A X=%RANDOM%%%108% --------------- thanks to all!. bvb47 wrote: >Hello!, > >I'm trying to obtain a random number in batch file. > >if I type >> set /a X=%random%%108 >in command prompt work ok, but if I put this instruction in batch file, don't >work! > >anybody know why? > >thanks! -- Message posted via http://www.winserverkb.com |
|
|
|
#5 (permalink) |
|
Messages: n/a
Hébergeur: |
the solution is written by BSOD in nabble forum:
---------------- BSOD wrote: Cos in a batch %108 is interpreted as a command line parameter passed to the . bat, the same as %0 and %1 etc etc. use this : SET /A X=%RANDOM%%%108% --------------- thanks to all!. bvb47 wrote: >Hello!, > >I'm trying to obtain a random number in batch file. > >if I type >> set /a X=%random%%108 >in command prompt work ok, but if I put this instruction in batch file, don't >work! > >anybody know why? > >thanks! -- Message posted via http://www.winserverkb.com |
|
![]() |
| Outils de la discussion | |
|
|