18

I want to display a process's command line (including any arguments) from the command line itself. In other words, I want to show the "Command Line" column in the Task Manager but from a command line. Is this possible?

For example, the output might look something like

C:\java\bin\java.exe -Dhttp.proxyHost=http://localproxy -Dport=8331
user35042
  • 2,681
  • 12
  • 34
  • 60
  • 2
    [How do I find out command line arguments of a running program?](https://superuser.com/q/415360/241386) – phuclv Jan 29 '18 at 10:12

2 Answers2

26

Wmic.exe will show you what you are looking for:

wmic path win32_process get name,commandline > commandline.txt

Java looks like:

"C:\Program Files\Java\jre6\bin\jqs.exe" -service -config "C:\Program Files\Java\jre6\lib\deploy\jqs\jqs.conf"

For all available attributes, try:

wmic path win32_process get /format:list
RobW
  • 2,806
  • 1
  • 19
  • 22
  • 1
    I am getting error "Invalid GET expression" for the comma put between name and commandline. Rest all is working like charm. – Krishna Pandey Jan 07 '16 at 19:57
  • I'm guessing you're running this within a batch file? try escaping the comma like so: "wmic path win32_process get name^, commandline" – RobW Jan 08 '16 at 00:16
  • 1
    I was running it from powershell, will try this and update. – Krishna Pandey Jan 08 '16 at 05:19
  • 1
    Ok - If you issue the 'all available attributes command' noted above, in powershell, you get expected results. On reading further, in power shell, the comma does indeed need to be escaped. However, you use the forward quote: ` to do so: wmic path win32_process get name`, commandline – RobW Jan 18 '16 at 18:06
  • 2
    If you're running the first command, remove the space after the comma so that it looks like this: `wmic path win32_process get name,commandline > commandline.txt` That will remove the "Invalid GET expression" error – John M. Wright Mar 06 '17 at 19:18
  • 2
    +1 thank you! Process Explorer fails if the command line is too long, but this command works just fine! – user541686 Jan 18 '19 at 10:02
  • 1
    You can also pipe the output of `wmic` to `findstr java` for example – Panki Oct 11 '21 at 14:01
  • wmic.exe is no longer provided in windows. https://learn.microsoft.com/en-us/windows/win32/wmisdk/wmic – J Decker Aug 24 '23 at 22:27
13

You can use Microsoft's official Process Explorer. It can do exactly this and has many many more useful features.

Uwe Keim
  • 2,420
  • 5
  • 30
  • 47
mailq
  • 17,023
  • 2
  • 37
  • 69
  • 2
    One very useful note, after starting Process Explorer for the first time, right-click the table header ("Process" | "CPU" | "Private Bytes" | etc.) and add the "Command Line" column for the info you want to see. Very, very helpful tool, allows you to see what scripts IT is running on your machine... – xmnboy Jan 06 '18 at 00:11