Variable output is being truncated

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
gmgbfisher
Posts: 2
Joined: 18 Aug 2011 14:09

Variable output is being truncated

#1 Post by gmgbfisher » 18 Aug 2011 14:19

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?

Batcher
Posts: 74
Joined: 16 Apr 2009 10:36

Re: Variable output is being truncated

#2 Post by Batcher » 19 Aug 2011 00:40

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

gmgbfisher
Posts: 2
Joined: 18 Aug 2011 14:09

Re: Variable output is being truncated

#3 Post by gmgbfisher » 22 Aug 2011 07:10

Those two options worked great. Thank you Batcher.

Post Reply