• 0

.BAT Questions - Stumpted


Question

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

4 answers to this question

Recommended Posts

  • 0
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

  • 0

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

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.