Wednesday, November 11, 2015

why does batch file execute different lines than what it contains


i typed this line in a bat file (pause just to see what got typed)


    start my_program -m y -f %s_%d_fix -z n
pause

it ends up running this


    start my_program -m y -f d_fix -z n

as you can see the %s_% part gets removed
i tried looking for wether the % caused reading the lines differently but it's just fine when typing in cmd
the launched program gets incorrect arguments, any thoughts on this? thanks.


Answer



Windows Cmd and MS-DOS Command.com use % to indicate environment variables. In your case, %s_% is interpreted as a variable expansion (with s_ acting as the variable's name), and is expanded to an empty string.


To preserve the % sign unaltered, use %%s_%%d_fix.


No comments:

Post a Comment

linux - How to SSH to ec2 instance in VPC private subnet via NAT server

I have created a VPC in aws with a public subnet and a private subnet. The private subnet does not have direct access to external network. S...