从Windows任务列表返回命令行

从Windows任务列表返回命令行

问题描述:

我正在搜索命令以获取在Windows任务管理器中编写的命令行.我使用的是tasklist /fo CSV /v,但是当我查看任务管理器时,它没有提供我得到的命令行.我附上一张图片以显示我的意思,这是最右边的列.

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.

我在r内的系统调用中需要此信息.

I need this information in a system call within r.

仅出于完整性考虑:

#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)