returning command line from windows tasklist

99封情书 提交于 2019-12-11 03:13:00

问题


I am searching for a command to get the command line written in the windows task manager. I was using tasklist /fo CSV /v but it doesn't provide the command line I get when I look at the task manager. I attach a picture to show what I mean, it is the right most column.

I need this information in a system call within r.


回答1:


Just for completeness:

#get list of processes' ids and exec paths
res <- system("wmic process get ProcessID,CommandLine", intern=TRUE)

#parse the results to get a nice data.frame
ans <- trimws(res)[!grepl("^[0-9]", trimws(res))]
ans <- ans[ans!=""][-1]
data.frame(
    ProcessId=sapply(strsplit(ans, " "), tail, n=1L),
    CommandLine=sapply(strsplit(ans, " "), function(x) trimws(paste(head(x, n=-1L), collapse=" ")))
)
head(df)


来源:https://stackoverflow.com/questions/48901500/returning-command-line-from-windows-tasklist

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