Page 1 of 1

Variable output is being truncated

Posted: 18 Aug 2011 14:19
by gmgbfisher
I'm writing a bat file to allow users to select printers to install. The black and white printers all have B&W in their name. The variable looks something like this: set printername=printer_name_b&w. The problem is that the output from the variable keeps dropping the "&w". Is there any way I can force the bat file to keep the "&w" or is it just easier to drop the & in the printer names?

Re: Variable output is being truncated

Posted: 19 Aug 2011 00:40
by Batcher

Code: Select all

@echo off
rem method 1
set "printername=printer_name_b&w"
echo "%printername%"

rem method 2
set "printername=printer_name_b^&w"
echo %printername%

rem method 3
setlocal enabledelayedexpansion
set "printername=printer_name_b&w"
echo !printername!
pause

Re: Variable output is being truncated

Posted: 22 Aug 2011 07:10
by gmgbfisher
Those two options worked great. Thank you Batcher.