Saturday 15 August 2015

windows - CMD how to pass parameters to script and save to file name of one of the parameters -



windows - CMD how to pass parameters to script and save to file name of one of the parameters -

i want pass next parameters script:

myscript.cmd "foo" "bar" "file"

where 3rd parameter should added extension .log

in illustration should file.log

set logfile = "%~3" + .log echo logfilename "%logfile%" echo %date% %time% got parameters "%~1" "%~2" >> "%logfile%"

should script above, not beingness able create work

three problems, quotes (included in value of variable), spaces (you have included spaces in name of variable) , concatenation (there no concatenation operator in batch files)

you have defined variable named logfile_, aditional space (represented underscore) in name, , assigned value literal _"file"_+_.log (as before, underscores represent spaces)

the line

set logfile = "%~3" + .log ^ ^^ ^^^^ unneeded/problematic characters

should

set "logfile=%~3.log"

no aditional spaces , quotes not included in value, delimit assignment prevent problems special characters or aditional spaces @ end of line

windows command-line cmd dos

No comments:

Post a Comment