variables and .bat files

August 6, 2010 at 16:24:26
Specs: Windows 7
I have an environment variable that starts with a 3, so when I call it in the .bat file, it truncates the 3 and then makes the path invalid. For example:

"%3DSMAX_2011x64_PATH%\3dsmax.exe" turns into "C:\Program Files\Autodesk\ds Max 2011\3dsmax.exe " where "ds Max 2011" should be "3ds Max 2011".

I can't change the name of the Environment variable, and executing the same line in the command line works just fine, so I know this can be done, I'm just not sure how.

Any help would be appreciated.


See More: variables and .bat files

Report •


#1
August 6, 2010 at 16:53:25
Ack. That should be:

"%3DSMAX_2011x64_PATH%\3dsmax.exe" turns into "DSMAX_2011x64_PATH\3dsmax.exe "


Report •

#2
August 6, 2010 at 17:03:13
No guarantees here, but try escaping it with ^

"^%3DSMAX_2011x64_PATH%\3dsmax.exe"


Report •

#3
August 6, 2010 at 17:39:16
Unfortunately, that does not work... Thanks though!

Report •

Related Solutions

#4
August 6, 2010 at 17:46:15
Try using:

"%%3DSMAX_2011x64_PATH%%\3dsmax.exe"

Instead of:

"%3DSMAX_2011x64_PATH%%\3dsmax.exe"

(Double Percentage)


Report •

#5
August 6, 2010 at 17:54:18
No dice there, either...

Report •

#6
August 6, 2010 at 17:55:10
Dang, I'm out of ideas then, Sorry mate.

Report •

#7
August 6, 2010 at 19:24:50
I can tell you that %3 is being expanded to a parameter, I know of no way to stop this happening, but it can be worked around:

rem with delayed expansion the parameter
rem doesn't exist in the string
SetLocal EnableDelayedExpansion
echo "!3DSMAX_2011x64_PATH!\3dsmax.exe"

or

rem using set (variable can't start with "=")
for /f "tokens=1* delims==" %%a in ('set 3DSMAX_2011x64_PATH') do (
    if "%%a"=="3DSMAX_2011x64_PATH" echo "%%b\3dsmax.exe"
)


Tested on xp...


Report •

#8
August 9, 2010 at 11:11:08
This worked great, thanks! I wound up doing this:

for /f "tokens=1* delims==" %%a in ('set 3DSMAX_2011x64_PATH') do (
if "%%a"=="3DSMAX_2011x64_PATH" set MaxDir64=%%b
)

and using that MaxDir64 variable to do some copy and run operations.


Report •


Ask Question