How to retrieve available RAM from Windows command line?

前端 未结 11 671
-上瘾入骨i
-上瘾入骨i 2020-12-23 09:44

Is there a command line utility within Windows or third-party program that can retrieve available RAM on a machine? (Since I don\'t believe this can be done in pure JAVA, si

相关标签:
11条回答
  • 2020-12-23 10:22

    This cannot be done in pure java. But you can run external programs using java and get the result.

    Process p=Runtime.getRuntime().exec("systeminfo");
    Scanner scan=new Scanner(p.getInputStream());
    while(scan.hasNext()){
        String temp=scan.nextLine();
        if(temp.equals("Available Physical Memmory")){
           System.out.println("RAM :"temp.split(":")[1]);
           break;
        }
    }
    
    0 讨论(0)
  • 2020-12-23 10:24

    Just in case you need this functionality in a Java program, you might want to look at the sigar API: http://www.hyperic.com/products/sigar

    Actually, this is no answer to the question, I know, but a hint so you don't have to reinvent the wheel.

    0 讨论(0)
  • 2020-12-23 10:32
    wmic OS get FreePhysicalMemory /Value
    
    0 讨论(0)
  • 2020-12-23 10:34

    There is a whole bunch of useful low level tools from SysSnternals.

    And psinfo may be the most useful.

    I used the following psinfo switches:

    -h        Show installed hotfixes.
    -d        Show disk volume information.
    

    Sample output is this:

    c:> psinfo \\development -h -d
    
    PsInfo v1.6 - local and remote system information viewer
    Copyright (C) 2001-2004 Mark Russinovich
    Sysinternals - www.sysinternals.com
    
    
    System information for \\DEVELOPMENT:
    Uptime: 28 days, 0 hours, 15 minutes, 12 seconds
    Kernel version: Microsoft Windows XP, Multiprocessor Free
    Product type Professional
    Product version: 5.1
    Service pack: 0
    Kernel build number: 2600
    Registered organization: Sysinternals
    Registered owner: Mark Russinovich
    Install date: 1/2/2002, 5:29:21 PM
    Activation status: Activated
    IE version: 6.0000
    System root: C:\WINDOWS
    Processors: 2
    Processor speed: 1.0 GHz
    Processor type: Intel Pentium III
    Physical memory: 1024 MB
    Volume Type Format Label Size Free Free
    A: Removable 0%
    C: Fixed NTFS WINXP 7.8 GB 1.3 GB 16%
    D: Fixed NTFS DEV 10.7 GB 809.7 MB 7%
    E: Fixed NTFS SRC 4.5 GB 1.8 GB 41%
    F: Fixed NTFS MSDN 2.4 GB 587.5 MB 24%
    G: Fixed NTFS GAMES 8.0 GB 1.0 GB 13%
    H: CD-ROM CDFS JEDIOUTCAST 633.6 MB 0%
    I: CD-ROM 0% Q: Remote 0%
    T: Fixed NTFS Test 502.0 MB 496.7 MB 99%
    OS Hot Fix Installed
    Q147222 1/2/2002
    Q309521 1/4/2002
    Q311889 1/4/2002
    Q313484 1/4/2002
    Q314147 3/6/2002
    Q314862 3/13/2002
    Q315000 1/8/2002
    Q315403 3/13/2002
    Q317277 3/20/2002
    
    0 讨论(0)
  • 2020-12-23 10:37

    Bit old but I wanted to know similar. Just adding the solution I came across since IMO the best answer came from Everardo w/ Physical Memory

    wmic OS get FreePhysicalMemory /Value

    This lead me to look deeper into wmic... Keep in mind Free Physical Memory is not the type to look at.

    wmic OS get FreePhysicalMemory,FreeVirtualMemory,FreeSpaceInPagingFiles /VALUE

    This returns something like...

    FreePhysicalMemory=2083440
    FreeSpaceInPagingFiles=3636128
    FreeVirtualMemory=842124
    
    0 讨论(0)
  • 2020-12-23 10:39
    PS C:\Users\Rack> systeminfo | findstr "System Memory"
    System Boot Time:          5/5/2016, 11:10:41 PM
    System Manufacturer:       VMware, Inc.
    System Model:              VMware Virtual Platform
    System Type:               x64-based PC
    System Directory:          C:\Windows\system32
    System Locale:             en-us;English (United States)
    Total Physical Memory:     40,959 MB
    Available Physical Memory: 36,311 MB
    Virtual Memory: Max Size:  45,054 MB
    Virtual Memory: Available: 41,390 MB
    Virtual Memory: In Use:    3,664 MB
    
    0 讨论(0)
提交回复
热议问题