pass arguments from batch file to VBScript File -
i trying pass arguments batch file vb script file.
set inputfile ="c:\temp\inputfile_mod.csv" set outputfile = "c:\temp\outputfile.dat"
i tried pass variables below not getting vbscript file.
cscript sfevbmacro.vbs inputfile outputfile
but if pass direct path of files below working fine
cscript sfevbmacro.vbs c:\temp\inputfile_mod.csv c:\temp\outputfile.dat.
is there wrong in passing arguments variables?
vbscript code:
set args = wscript.arguments inputfile = wscript.arguments.unnamed(0) createdfilepath = wscript.arguments.unnamed(1) sub readcsvfile() set objfiletoread = objfso.opentextfile(inputfile,1) rem read csv file end sub readcsvfile
can can please.
there 2 problems in code. first 1 variable assignment
set inputfile ="c:\temp\inputfile_mod.csv" ^ set outputfile = "c:\temp\outputfile.dat" ^ ^
the spaces indicated included in variable name (when placed in left side of equal) , in value stored (right side of equal)
it habit quote value assignment prevent problems special characters, recomended syntax is
set "inputfile=c:\temp\inputfile_mod.csv" set "outputfile=c:\temp\outputfile.dat"
where quotes protect assignment, there no spaces around equal sign , note that, syntax, quotes not stored in variable value.
the second problem how use variables. vbscript code not expect 2 variable names, 2 file names. so, don't have pass variable names, values stored inside them. in batch files done using %varname%
.
set "inputfile=c:\temp\inputfile_mod.csv" set "outputfile=c:\temp\outputfile.dat" cscript sfevbmacro.vbs "%inputfile%" "%outputfile%"
the batch parser replace variable read operation value inside variable , execute command.
if prefer pass variable names (your original code) instead of variable values, can it, vbscript should changed retrieve variables contents
with wscript.createobject("wscript.shell").environment("process") inputfile = .item( wscript.arguments.unnamed(0) ) createdfilepath = .item( wscript.arguments.unnamed(1) ) end
as code receives environment variable names, need use environment
property of wscript.shell
instance retrieve variable contents process environment.
Comments
Post a Comment