I know it's VBScript, but about eval()...

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
orange_batch
Expert
Posts: 442
Joined: 01 Aug 2010 17:13
Location: Canadian Pacific
Contact:

I know it's VBScript, but about eval()...

#1 Post by orange_batch » 13 May 2011 01:47

I've read in the past that eval() is bad because it can be abused. I've seen that said about JavaScript in particular, but isn't it the same with any language??

Here are two very simple examples.

Say I want to do a calculation from DOS using VBScript:

Code: Select all

cscript math.vbs //nologo 100*5

math.vbs:

Code: Select all

wscript.echo eval(wscript.arguments(0))


Say we want do to something with variables:

Code: Select all

cscript cake.vbs //nologo banana

cake.vbs:

Code: Select all

chocolatecake="yum chocolate"
bananacake="yum bananas"
wscript.echo eval(wscript.arguments(0)&"cake")


Is there a proper way to do these? Or is this right?

Thanks!

amel27
Expert
Posts: 177
Joined: 04 Jun 2010 20:05
Location: Russia

Re: I know it's VBScript, but about eval()...

#2 Post by amel27 » 13 May 2011 04:13

Code: Select all

wscript.echo eval(wscript.arguments(0)&"&""cake""")

Post Reply