How to check for $ProgramFiles(x86) ?

222 views
Skip to first unread message

Timothy Madden

unread,
Oct 24, 2012, 4:25:55 PM10/24/12
to vim...@googlegroups.com
Hello

I am trying to see if the current system is 32-bit or 64-bit Windows. On
64-bit Windows the environment variable $ProgramFiles(x86) is known to
exits, but Vim will just check for $ProgramFiles and the appendthe
'(x86)' part. Is there a way to check if the environment variable
$ProgramFiles(x86) exists in the current environment ?

I tried both expand('$ProgramFiles(x86)') and
exists('$ProgramFiles(x86)'), both of them check the '$ProgamFiles' part
only.

Thank you,
Timothy Madden

Gerald Klein

unread,
Oct 24, 2012, 4:27:11 PM10/24/12
to vim...@googlegroups.com
What your doing I would think would work, but check in the system applet in control panel. 



--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php



--

Gerald Klein DBA

Cont...@geraldklein.com

www.geraldklein.com

geraldklein.wordpress.com

j...@zognet.com

708-599-0352


Arch Awesome, Ranger & Vim the coding triple threat.

Linux registered user #548580 



Ben Fritz

unread,
Oct 24, 2012, 4:41:09 PM10/24/12
to vim...@googlegroups.com, vim_dev
:help expand-environment-var says that only letters, digits, and _ are allowed in the environment variable name. I am not sure whether there is a workaround.

Perhaps Vim needs to allow a different set of characters for Windows environment variables, or some way to escape the characters to indicate they are part of the name.

Gary Johnson

unread,
Oct 24, 2012, 5:25:22 PM10/24/12
to vim...@googlegroups.com
I think the following or a variation should do it. I was only able
to test it on names without parentheses as I didn't see any variable
names with them in my environment.

split(system('set ProgramFiles(x86)', '=')[1]

gets the value and

system('set ProgramFiles(x86)') =~ 'not defined'

will evaluate to true if the variable is not defined.

Regards,
Gary

Ben Fritz

unread,
Oct 24, 2012, 5:50:04 PM10/24/12
to vim...@googlegroups.com, gary...@spocom.com
On Wednesday, October 24, 2012 4:25:41 PM UTC-5, Gary Johnson wrote:
>
> I think the following or a variation should do it. I was only able
> to test it on names without parentheses as I didn't see any variable
> names with them in my environment.
>
> split(system('set ProgramFiles(x86)', '=')[1]
>
> gets the value and
>
> system('set ProgramFiles(x86)') =~ 'not defined'
>
> will evaluate to true if the variable is not defined.
>

Not quite. You get hit by Windows *#$&#ing command-line quoting.

This works for me:

:echo system('set PROGRAMFILES^(x86^)')

George V. Reilly

unread,
Oct 24, 2012, 6:09:28 PM10/24/12
to vim...@googlegroups.com, gary...@spocom.com
In the past, I've solved very similar problems with batch files [1]
and Bash scripts [2].
The parentheses in the environment variable name are asinine.

[1] http://weblogs.asp.net/george_v_reilly/archive/2009/09/11/launching-32-bit-applications-from-batchfiles-on-win64.aspx
@setlocal
@set _pf=%ProgramFiles%
@if not "[%ProgramFiles(x86)%]"=="[]" set _pf=%ProgramFiles(x86)%
@start "" /b "%_pf%\SourceGear\DiffMerge\DiffMerge.exe" %*

[2] http://thread.gmane.org/gmane.comp.gnu.mingw.user/31262/focus=31273
#!/bin/sh
pf=`env | sed -n s,'^PROGRAMFILES(X86)=',,p`
if [ -z "$pf" ]; then pf="$PROGRAMFILES"; fi
"$pf/SourceGear/DiffMerge/DiffMerge.exe" $*
--
/George V. Reilly geo...@reilly.org Twitter: @georgevreilly
http://www.georgevreilly.com/blog http://blogs.cozi.com/tech

Timothy Madden

unread,
Oct 25, 2012, 6:51:55 PM10/25/12
to vim...@googlegroups.com
Thank you for your answers. I think a simple
let l:pf = system('Echo %ProgramFiles(x86)%')
if l:pf == '%ProgramFiles(x86)%'
...
will work well enough.

Thank you,
Timothy Madden

John Little

unread,
Oct 25, 2012, 8:04:07 PM10/25/12
to vim...@googlegroups.com, vim...@googlegroups.com
FWIW, on Unix if you manage to get such a variable into the environment (bash won't let you)

:echo libcall('', 'getenv', '$ProgramFiles(x86)')

will show it to you.

Surely, there's a better way.

Regards, John

Reply all
Reply to author
Forward
0 new messages