PC Review


Reply
Thread Tools Rate Thread

Any way to escape parenthesis characters in a batch file?

 
 
WB
Guest
Posts: n/a
 
      27th Mar 2008
if "%PROCESSOR_ARCHITECTURE%"=="x86" (
set PROGNAME=Program Files
) else if "%PROCESSOR_ARCHITECTURE%"=="AMD64" (
set PROGNAME=Program Files (x86)
)

This fails because of the parenthesis in (x86). I have a workaround already,
but I'd prefer using the method above for readability. Any way to escape the
parenthesis characters so this will work?

--
Bill Baker
 
Reply With Quote
 
 
 
 
Big Al
Guest
Posts: n/a
 
      28th Mar 2008
WB wrote:
> if "%PROCESSOR_ARCHITECTURE%"=="x86" (
> set PROGNAME=Program Files
> ) else if "%PROCESSOR_ARCHITECTURE%"=="AMD64" (
> set PROGNAME=Program Files (x86)
> )
>
> This fails because of the parenthesis in (x86). I have a workaround already,
> but I'd prefer using the method above for readability. Any way to escape the
> parenthesis characters so this will work?
>

I didn't think .bat files would accept if/else commands.
I know 'if exists ... goto' works. I use it to skip to another line in
a batch file, and thus the next line is the else.
But not much else you can do.
 
Reply With Quote
 
Colin Barnhorst
Guest
Posts: n/a
 
      28th Mar 2008
Can you use the short file name for Program Files (x86)? It is "PROGRA~2".
Or is that your workaround?

"WB" <(E-Mail Removed)> wrote in message
news:C713DAEC-73F3-42FB-ABE5-(E-Mail Removed)...
> if "%PROCESSOR_ARCHITECTURE%"=="x86" (
> set PROGNAME=Program Files
> ) else if "%PROCESSOR_ARCHITECTURE%"=="AMD64" (
> set PROGNAME=Program Files (x86)
> )
>
> This fails because of the parenthesis in (x86). I have a workaround
> already,
> but I'd prefer using the method above for readability. Any way to escape
> the
> parenthesis characters so this will work?
>
> --
> Bill Baker


 
Reply With Quote
 
Big Al
Guest
Posts: n/a
 
      28th Mar 2008
WB wrote:
> if "%PROCESSOR_ARCHITECTURE%"=="x86" (
> set PROGNAME=Program Files
> ) else if "%PROCESSOR_ARCHITECTURE%"=="AMD64" (
> set PROGNAME=Program Files (x86)
> )
>
> This fails because of the parenthesis in (x86). I have a workaround already,
> but I'd prefer using the method above for readability. Any way to escape the
> parenthesis characters so this will work?
>

see http://home7.inet.tele.dk/batfiles/batfiles.htm
I was partially right. Use the GOTO to get to another line of code

if ........... goto OKAY
rem here if IF is false
goto END

:OKAY
rem here if IF is true
goto END


:END
rem here on both.
 
Reply With Quote
 
Pegasus \(MVP\)
Guest
Posts: n/a
 
      28th Mar 2008

"Big Al" <(E-Mail Removed)> wrote in message
news:JLWGj.9189$Oj5.1280@trnddc06...
> WB wrote:
>> if "%PROCESSOR_ARCHITECTURE%"=="x86" (
>> set PROGNAME=Program Files
>> ) else if "%PROCESSOR_ARCHITECTURE%"=="AMD64" (
>> set PROGNAME=Program Files (x86)
>> )
>>
>> This fails because of the parenthesis in (x86). I have a workaround
>> already, but I'd prefer using the method above for readability. Any way
>> to escape the parenthesis characters so this will work?
>>

> I didn't think .bat files would accept if/else commands.
> I know 'if exists ... goto' works. I use it to skip to another line in a
> batch file, and thus the next line is the else.
> But not much else you can do.


They actually do. Try this for fun:

@echo off
if %UserName%==Al (echo Hello Al) else (echo Goodby %Username%)


 
Reply With Quote
 
Pegasus \(MVP\)
Guest
Posts: n/a
 
      28th Mar 2008

"WB" <(E-Mail Removed)> wrote in message
news:C713DAEC-73F3-42FB-ABE5-(E-Mail Removed)...
> if "%PROCESSOR_ARCHITECTURE%"=="x86" (
> set PROGNAME=Program Files
> ) else if "%PROCESSOR_ARCHITECTURE%"=="AMD64" (
> set PROGNAME=Program Files (x86)
> )
>
> This fails because of the parenthesis in (x86). I have a workaround
> already,
> but I'd prefer using the method above for readability. Any way to escape
> the
> parenthesis characters so this will work?
>
> --
> Bill Baker


Try this:
@echo off
if "%PROCESSOR_ARCHITECTURE%"=="x86" (
set PROGNAME=Program Files
) else (
if "%PROCESSOR_ARCHITECTURE%"=="AMD64" set PROGNAME=Program Files (x86)
)


 
Reply With Quote
 
WB
Guest
Posts: n/a
 
      28th Mar 2008
This is pretty much the same code I had. Unfortunately it sets PROGNAME as
"Program Files (x86" with the missing closed parenthesis.

My workaround is as follows:
SET PROGNAME=Program Files (x86)
IF "%PROCESSOR_ARCHITECTURE%"=="x86" SET PROGNAME=Program Files

This will also work if PROCESSOR_ARCHITECTURE changes to "AMD128", or
"Intel128" like it should be .
--
Bill Baker


"Pegasus (MVP)" wrote:

>
> "WB" <(E-Mail Removed)> wrote in message
> news:C713DAEC-73F3-42FB-ABE5-(E-Mail Removed)...
> > if "%PROCESSOR_ARCHITECTURE%"=="x86" (
> > set PROGNAME=Program Files
> > ) else if "%PROCESSOR_ARCHITECTURE%"=="AMD64" (
> > set PROGNAME=Program Files (x86)
> > )
> >
> > This fails because of the parenthesis in (x86). I have a workaround
> > already,
> > but I'd prefer using the method above for readability. Any way to escape
> > the
> > parenthesis characters so this will work?
> >
> > --
> > Bill Baker

>
> Try this:
> @echo off
> if "%PROCESSOR_ARCHITECTURE%"=="x86" (
> set PROGNAME=Program Files
> ) else (
> if "%PROCESSOR_ARCHITECTURE%"=="AMD64" set PROGNAME=Program Files (x86)
> )
>
>
>

 
Reply With Quote
 
Colin Barnhorst
Guest
Posts: n/a
 
      28th Mar 2008
You never did comment on whether "progra~2" could work for you. Can't you
use the short filename?

"WB" <(E-Mail Removed)> wrote in message
news:C49F7B14-DDF4-4F6E-9BF6-(E-Mail Removed)...
> This is pretty much the same code I had. Unfortunately it sets PROGNAME as
> "Program Files (x86" with the missing closed parenthesis.
>
> My workaround is as follows:
> SET PROGNAME=Program Files (x86)
> IF "%PROCESSOR_ARCHITECTURE%"=="x86" SET PROGNAME=Program Files
>
> This will also work if PROCESSOR_ARCHITECTURE changes to "AMD128", or
> "Intel128" like it should be .
> --
> Bill Baker
>
>
> "Pegasus (MVP)" wrote:
>
>>
>> "WB" <(E-Mail Removed)> wrote in message
>> news:C713DAEC-73F3-42FB-ABE5-(E-Mail Removed)...
>> > if "%PROCESSOR_ARCHITECTURE%"=="x86" (
>> > set PROGNAME=Program Files
>> > ) else if "%PROCESSOR_ARCHITECTURE%"=="AMD64" (
>> > set PROGNAME=Program Files (x86)
>> > )
>> >
>> > This fails because of the parenthesis in (x86). I have a workaround
>> > already,
>> > but I'd prefer using the method above for readability. Any way to
>> > escape
>> > the
>> > parenthesis characters so this will work?
>> >
>> > --
>> > Bill Baker

>>
>> Try this:
>> @echo off
>> if "%PROCESSOR_ARCHITECTURE%"=="x86" (
>> set PROGNAME=Program Files
>> ) else (
>> if "%PROCESSOR_ARCHITECTURE%"=="AMD64" set PROGNAME=Program Files
>> (x86)
>> )
>>
>>
>>


 
Reply With Quote
 
Pegasus \(MVP\)
Guest
Posts: n/a
 
      28th Mar 2008
My suggestion may have been pretty much the same as
your own code, with a slight difference: It was able to handle
if-then-else statements. Your work-around is, of course,
an excellent alternative solution.


"WB" <(E-Mail Removed)> wrote in message
news:C49F7B14-DDF4-4F6E-9BF6-(E-Mail Removed)...
> This is pretty much the same code I had. Unfortunately it sets PROGNAME as
> "Program Files (x86" with the missing closed parenthesis.
>
> My workaround is as follows:
> SET PROGNAME=Program Files (x86)
> IF "%PROCESSOR_ARCHITECTURE%"=="x86" SET PROGNAME=Program Files
>
> This will also work if PROCESSOR_ARCHITECTURE changes to "AMD128", or
> "Intel128" like it should be .
> --
> Bill Baker



 
Reply With Quote
 
WB
Guest
Posts: n/a
 
      28th Mar 2008
The short filename method may work as well, but I prefer my workaround method
just for clean-looking code. Plus I just have a deep hatred for short
filenames, and there's always that one-in-a-million chance that something
will happen to make it "progra~3". We had an issue recently where a DOS
program had to look for a text file. A backup of the file had been made, and
somehow the two short filenames got switched, causing the DOS app to fail.
--
Bill Baker


"Colin Barnhorst" wrote:

> You never did comment on whether "progra~2" could work for you. Can't you
> use the short filename?
>
> "WB" <(E-Mail Removed)> wrote in message
> news:C49F7B14-DDF4-4F6E-9BF6-(E-Mail Removed)...
> > This is pretty much the same code I had. Unfortunately it sets PROGNAME as
> > "Program Files (x86" with the missing closed parenthesis.
> >
> > My workaround is as follows:
> > SET PROGNAME=Program Files (x86)
> > IF "%PROCESSOR_ARCHITECTURE%"=="x86" SET PROGNAME=Program Files
> >
> > This will also work if PROCESSOR_ARCHITECTURE changes to "AMD128", or
> > "Intel128" like it should be .
> > --
> > Bill Baker
> >
> >
> > "Pegasus (MVP)" wrote:
> >
> >>
> >> "WB" <(E-Mail Removed)> wrote in message
> >> news:C713DAEC-73F3-42FB-ABE5-(E-Mail Removed)...
> >> > if "%PROCESSOR_ARCHITECTURE%"=="x86" (
> >> > set PROGNAME=Program Files
> >> > ) else if "%PROCESSOR_ARCHITECTURE%"=="AMD64" (
> >> > set PROGNAME=Program Files (x86)
> >> > )
> >> >
> >> > This fails because of the parenthesis in (x86). I have a workaround
> >> > already,
> >> > but I'd prefer using the method above for readability. Any way to
> >> > escape
> >> > the
> >> > parenthesis characters so this will work?
> >> >
> >> > --
> >> > Bill Baker
> >>
> >> Try this:
> >> @echo off
> >> if "%PROCESSOR_ARCHITECTURE%"=="x86" (
> >> set PROGNAME=Program Files
> >> ) else (
> >> if "%PROCESSOR_ARCHITECTURE%"=="AMD64" set PROGNAME=Program Files
> >> (x86)
> >> )
> >>
> >>
> >>

>

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
coma + parenthesis characters junebug Windows XP Help 1 21st Feb 2008 07:23 PM
escape characters in *.settings file sklett Microsoft C# .NET 2 26th Sep 2007 12:41 AM
Escape { and } characters in config file Lonifasiko Microsoft C# .NET 3 5th Jul 2006 08:17 PM
international characters with dsadd in batch file Mihajlo Cvetanovic Microsoft Windows 2000 Active Directory 2 25th May 2004 11:06 AM
Specifying special characters as input to a batch file Albert Fuchigami Microsoft Windows 2000 CMD Promt 9 21st Jan 2004 04:48 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 02:28 PM.