How to retrieve available RAM from Windows command

2019-03-08 10:41发布

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, since it is run within a virtual machine, that has preset / allocated RAM)?

11条回答
走好不送
2楼-- · 2019-03-08 10:56

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
查看更多
祖国的老花朵
3楼-- · 2019-03-08 10:56

Try MemLog. It does the job perfectly and quickly.

Download via one of many mirrors, e.g. this one: SoftPedia page for MemLog.
(MemLog's author has a web site. But this is down some times. Wayback machine snapshot here.)

Example output:

C:\>memlog
2012/02/01,13:22:02,878956544,-1128333312,2136678400,2138578944,-17809408,2147352576

878956544 being the free memory

查看更多
太酷不给撩
4楼-- · 2019-03-08 11:03
wmic OS get FreePhysicalMemory /Value
查看更多
劫难
5楼-- · 2019-03-08 11:07
wmic OS get TotalVisibleMemorySize /Value

Note not TotalPhysicalMemory as suggested elsewhere

查看更多
贪生不怕死
6楼-- · 2019-03-08 11:07

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;
    }
}
查看更多
登录 后发表回答