List MS Windows tasks

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-08 08:39:26

问题


Is there a "built-in" way to list all MS Windows tasks currently running?

I've googled a bit and found a workaround via shell("tasklist"), but I don't really like the structure of the resulting R object as its pretty "captured-output-only" like (i.e. the resulting object is a character vector containing things like line numbers etc.) and I would have to fire some regular expressions at it to turn it into something like a data frame or the like:

value <- shell("tasklist", intern=TRUE)

> value
 [1] ""                                                                               
 [2] "Abbildname                     PID Sitzungsname       Sitz.-Nr. Speichernutzung"
 [3] "========================= ======== ================ =========== ==============="
 [4] "System Idle Process              0 Services                   0            24 K"
 [5] "System                           4 Services                   0         9.404 K"

 [...]

[96] "tasklist.exe                  6876 Console                    1         6.040 K"

回答1:


This will return the information in a data frame:

> value <- read.csv(text = shell("tasklist /fo csv", intern = TRUE))
> head(value)
           Image.Name PID Session.Name Session. Mem.Usage
1 System Idle Process   0     Services        0      20 K
2              System   4     Services        0   1,652 K
3            smss.exe 328     Services        0     292 K
4           csrss.exe 468     Services        0   2,140 K
5         wininit.exe 548     Services        0     244 K
6           csrss.exe 564      Console        1  22,416 K

Also try:

View(value)


来源:https://stackoverflow.com/questions/14320987/list-ms-windows-tasks

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!