Search code examples
rwindowstasklist

returning command line from windows tasklist


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.

Task-Manager

I need this information in a system call within r.


Solution

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