如何在Ant中辨別OS是使用32位元還是64位元?

一開始想說可以透過os.arch去判斷, 但發現os.arch值是跟著JVM的! 舉例而言: 64-bit JVM值可能會顯示x64, amd64 or x86_64 32-bit JVM值會顯示x86 or i386

這會導致無法正確判斷使用者的OS是哪一種Arch.

經過小弟研究與Swind討論出一個可以在Windows2008、Windows2003、Win7、SLES、RHEL、Ubuntu、CentOS上正確取得Arch的方法, 並且簡單! 如下:

<project name="project">
	<target name="checkOS">
		<condition property="os.linux">
			<os family="unix" />
		</condition>
		<condition property="os.windows">
			<os family="windows" />
		</condition>
		<echo>linux:${os.linux}</echo>
		<echo>windows:${os.windows}</echo>
	</target>
	<target name="getLinuxBit" depends="checkOS" if="os.linux">
		<exec executable="/bin/bash" outputproperty="linux-bit">
			<arg value="-c" />
			<arg value="getconf LONG_BIT" />
		</exec>
		<echo>linux bit=${linux-bit}</echo>
	</target>
	<target name="checkOSBit" depends="getLinuxBit">
		<property environment="env" />
		<condition property="os.32">
			<or>
				<equals arg1="${linux-bit}" arg2="32" />
				<and>
					<os family="windows" />
					<not>
						<contains string="${env.ProgramFiles(x86)}"
							substring="Program Files (x86)" />
					</not>
				</and>
			</or>
		</condition>
		<condition property="os.64">
			<or>
				<contains string="${env.ProgramFiles(x86)}" 
					substring="Program Files (x86)" />
					<equals arg1="${linux-bit}" arg2="64" />
			</or>
		</condition>
		<echo>os.64:${os.64}</echo>
		<echo>os.32:${os.32}</echo>
	</target>
</project>
有更簡單的方法請指教一下!

曾看過某OpenSource的C程式, 透過判斷SysWOW64來確認是否為64bit-Windows. 我想直接透過系統環境變數判斷也是一種不錯選擇! 在Linux部分曾想過抓HOSTTYPE來判斷, 但在ant執行時居然取得不到這個環境變數! 最後只好透過getconfig的方式.