justapger Posted April 5, 2009 Share Posted April 5, 2009 Ok, so I'm using %RANDOM%, to gen random numbers, but I need to write that to another .BAT file using the current .BAT file without it accualy writing the number%RANDOM% gened. Here's the OG code: @echo echo %random%%random%%random%%random%%random%%random%%random%%random%%random%%random%%random%%random%%random%%random%%random% >>drive\path\filename.bat When it's written to the other .BAT file it turns out to be somthing looking like this: echo 974827459219038058784369472384723420976563932785762383487589328946781264962461278464567816237846718624 But... I want it to look like this in the new .BAT file: echo %random%%random%%random%%random%%random%%random%%random%%random%%random%%random%%random%%random%%random%%random%%random% __________________________________________________________________________________________________ ALSO- Somthing similar is happening to this(I still want it to write it to a new .BAT file)(OG .BAT file code): @echo ping localhost -n 2 >nul >>drive\path\filename.bat This is what it turns out to be: ping localhost -n 2 (the >nul is missing, and it's very important.) This is what I want it to turn out to be: ping localhost -n 2 >nul __________________________________________________________________________________ One more thing. Is there anyway to avoid an error? Maybe somthing close to this?!?: if %ERROR% cls I've already tried: cls cls >nul (that is after the line that could potentaly pose an error. Thanks abunch. :-) AND NO THIS ISN'T FOR A VIRUS JUST DON'T EVEN ASK! p.s. Viruses using .BAT are childish compared to others. Link to comment Share on other sites More sharing options...
0 I8PP Posted April 5, 2009 Share Posted April 5, 2009 Use ^ to have CLI interpret % as just another character. Eg. ^%random^%^%random^%... etc Link to comment Share on other sites More sharing options...
0 justapger Posted April 5, 2009 Author Share Posted April 5, 2009 Use ^ to have CLI interpret % as just another character.Eg. ^%random^%^%random^%... etc This works when used with the ping as fallows: @echo ping localhost -n 2 ^>nul >>drive\path\filename.bat (Which is great!) But... This doesn't work with the %RANDOM%, it's final results are just "echo ^^^^^^". I've tried moving their placment around but jsut got varied results from nothing to giberish to that ^. I see what your say, and in theory it should work 100%, but it doesn't, it just deletes the contents that contains it. Link to comment Share on other sites More sharing options...
0 justapger Posted April 5, 2009 Author Share Posted April 5, 2009 I was thinking, is there a way to temp. disable what a viable means? I know how to do it, but would it be perminet? Here's what I was thinking about: set random=%random% Maybe? Because I would have no clue how to set %random% back to the acctual %random% value, I woulnd't know how to describe it mathematicly... Link to comment Share on other sites More sharing options...
0 I8PP Posted April 5, 2009 Share Posted April 5, 2009 Hm yes, it seems if i did echo ^%random^% without redirecting output i get what you want, but >> file.bat would jsut spit out the ^^^'s :hmm: Link to comment Share on other sites More sharing options...
Question
justapger
Ok, so I'm using %RANDOM%, to gen random numbers, but I need to write that to another .BAT file using the current .BAT file without it accualy writing the number%RANDOM% gened.
Here's the OG code:
When it's written to the other .BAT file it turns out to be somthing looking like this:
But... I want it to look like this in the new .BAT file:
__________________________________________________________________________________________________
ALSO-
Somthing similar is happening to this(I still want it to write it to a new .BAT file)(OG .BAT file code):
This is what it turns out to be:
(the >nul is missing, and it's very important.)
This is what I want it to turn out to be:
__________________________________________________________________________________
One more thing.
Is there anyway to avoid an error?
Maybe somthing close to this?!?:
I've already tried:
(that is after the line that could potentaly pose an error.
Thanks abunch. :-)
AND NO THIS ISN'T FOR A VIRUS JUST DON'T EVEN ASK!
p.s. Viruses using .BAT are childish compared to others.
Link to comment
Share on other sites
4 answers to this question
Recommended Posts