Beefy Boxes and Bandwidth Generously Provided by pair Networks RobOMonk
We don't bite newbies here... much
 
PerlMonks  

Re: How to know the Windows OS that perl is running on

by mr_mischief (Prior)
on Apr 28, 2011 at 19:34 UTC ( #901857=note: print w/ replies, xml ) Need Help??


in reply to How to know the Windows OS that perl is running on

There are a few answers here. They tend to be much more Windows-specific than Perl-specific, but then that means they work from any language.

http://ss64.com/nt/ver.html has a batch script which uses the ver command interpreter built-in command which will tell you the version and the processor architecture. I know a command line seems archaic to some Windows users, but it can still be useful. I'm sure you could find a way to do this without the batch file based on the information provided.

@Echo off Setlocal :: Get windows Version numbers For /f "tokens=2 delims=[]" %%G in ('ver') Do (set _version=%%G) For /f "tokens=2,3,4 delims=. " %%G in ('echo %_version%') Do (set _ma +jor=%%G& set _minor=%%H& set _build=%%I) Echo Major version: %_major% Minor Version: %_minor%.%_build% if "%_major%"=="5" goto sub5 if "%_major%"=="6" goto sub6 Echo unsupported version goto:eof :sub5 ::Winxp or 2003 if "%_minor%"=="2" goto sub_2003 Echo Windows XP [%PROCESSOR_ARCHITECTURE%] goto:eof :sub_2003 Echo Windows 2003 or XP 64 bit [%PROCESSOR_ARCHITECTURE%] goto:eof :sub6 if "%_minor%"=="1" goto sub7 Echo Windows Vista or Windows 2008 [%PROCESSOR_ARCHITECTURE%] goto:eof :sub7 Echo Windows 7 or Windows 2008 R2 [%PROCESSOR_ARCHITECTURE%] goto:eof

http://ss64.com/ has command lists or statement dictionaries for:

They also have other information like links to the relevant MS KB entries when those apply, a Unicode character reference, an all-JavaScript password generator, and a forum. I'm not affiliated, not even as a forum member or regular user. I do enjoy their low-bandwidth and easily read pages when I just need to look up help for a command I don't have on the system I'm using at the moment. All the stuff here that is pulled from SS64 is of course copyright SS64. The site is even Creative Commons ShareAlike (Attribution-Non-Commercial-Share Alike 2.0 UK: England & Wales), so I have a local mirror or three of the whole site for my own use.It's only 14 MB -- see what I mean about low-bandwidth? Still, of course, if you're taking more than one complete mirror mirror your first mirror to do that.

If you can figure out all you need by parsing the environment variable %PROCESSOR_ARCHITECTURE% (which says x86 or IA64) then that'll be handy, but I think that returns x86 for 32-bit applications on 64-bit OSes. But then there's the Windows-on-Windows shim, and it has its own variable...

http://blogs.msdn.com/b/david.wang/archive/2006/03/26/howto-detect-process-bitness.aspx has a howto for determining if a 32-bit program is running on 64-bit Windows by using both PROCESSOR_ARCHITECTURE and PROCESSOR_ARCHITEW6432 but admits it's a bit of tickling the wizard.

There's also the HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\Session Manager\Environment\PROCESSOR_ARCHITECTURE registry key. You can even read this from a command line of:

reg query "HKLM\System\CurrentControlSet\Control\Session Manager\Envir +onment" /v PROCESSOR_ARCHITECTURE

Then there's the Microsoft Knowledge Base article on bit width of the OS: http://support.microsoft.com/kb/556009 complete with its own batch file which checks the registry a different way.

You Windows folks might want to give some love to configure and to Config so that $Config{'archname'} and $Config{'archname64'} end up being useful (if they're not now, which I assume is the case since nobody mentioned those). Having separate Win32 modules is all well and good for many things in areas in which you're trying to do complex things in ways Thompson, Kernighan, Ritchie, Pike, et al never intended. Yet I think it's not too much to ask that Perl users on Windows can tell easily what "Windows" means at the moment. Just expect the porters to not think it's too much to ask for Windows folks who care to do the work. Heck, even $^O might be made to return the information you want if you can provide the patch.

Hey, I'm a Linux guy. Who says it's hard to find relevant information using search engine? ;-) (Okay, I admit, I was an old DOS hand part of last century, and part of knowing what to search for was based on that.)


Comment on Re: How to know the Windows OS that perl is running on
Select or Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://901857]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (5)
As of 2014-04-21 05:37 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    April first is:







    Results (490 votes), past polls