|
server
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
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'twork! anybody know why? thanks! "bvb47 via WinServerKB.com" <u37442@uwe> wrote in message news:797b38778d19c@uwe...> Hello!, Try doubling the use of %:> > 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? 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 %. " "bvb47 via WinServerKB.com" <u37442@uwe> wrote in message news:797b38778d19c@uwe...Show quote > Hello!, At a command prompt I get:> > 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 > 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. 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! 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! |
|||||||||||||||||||||||