本文介绍了从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)

这篇关于从Windows任务列表返回命令行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-23 05:50