2013-01-14 45 views
1

是否有「內置」方式來列出當前正在運行的所有MS Windows任務?列表MS Windows任務

我google了一下,發現了一個解決方法,通過shell("tasklist"),但我真的不喜歡結果的R對象的結構,因爲它的漂亮的「捕獲輸出」像(即結果對象是一個字符含之類的行號等),我載體將不得不解僱一些正則表達式它把它變成像一個數據幀或類似:

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" 

回答

8

這將返回一個數據幀中的信息:

> 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 

另請嘗試:

View(value) 
+0

是的!非常酷的「命令行功夫」,我甚至不知道它的存在;-)非常感謝,男人! – Rappster