magicbennie
magicbennie

Reputation: 523

Batch - Pass variable parameters onto batch files that contain spaces

When my program finds itself outdated, it runs the updater 'data1.bat'.

In this case, i found that cmd was completely ignoring the double quotes in the command

This is the line of code (with variables(Original)):

start "" "%dirofbatch%data1.bat" "%downloc%" "%dirofbatch%" "%lver%" "%lget%"

This is the line of code (with those variables expanded):

start "" "C:\Users\Hello\Desktop\Minecraft Client\Versions\4.7\data1.bat" "\\SERVER\Users\Test User\Minecraft Hunger Games Client v4.8" "C:\Users\Hello\Desktop\Minecraft Client\Versions\4.7" "4.7" "4.8"

Instead of working, it seems to see:

start "" C:\Users\Hello\Desktop\Minecraft User\Minecraft Hunger Games

I found that out when every-time it ran, it started minecraft on my desktop, tried to login with the user name "User\Minecraft", the password "Hunger" and then tried to login to the server "Games"...

Is it possible to pass parameters with spaces to another batch program without this happening?

Upvotes: 2

Views: 351

Answers (1)

jeb
jeb

Reputation: 82202

It's a bug of START or better of cmd, if in the path of the command is a space and at least in one parameter it fails.

A workaround to add a CALL

start "" CALL "C:\Users\Hello\Desktop\Minecraft Client\Versions\4.7\data1.bat" "\\SERVER\Users\Test User\Minecraft Hunger Games Client v4.8" "C:\Users\Hello\Desktop\Minecraft Client\Versions\4.7" "4.7" "4.8"

Upvotes: 1

Related Questions