-
Notifications
You must be signed in to change notification settings - Fork 662
[node-core-library] Introduce a commandLine property to IProcessInfo that gets populated with the CLI that was passed into the process.
#5537
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
| /** | ||
| * The full command line of the process, when available. | ||
| * | ||
| * @remarks On some platforms this may be empty or truncated for kernel processes |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe a bit more specificity on which platforms would be good.
| if (line.includes('\t')) { | ||
| // Tab-delimited output (PowerShell path with CommandLine) | ||
| const win32Match: RegExpMatchArray | null = line.match( | ||
| /^\s*(?<ppid>\d+)\s+(?<pid>\d+)\s+(?<name>[^\s]+)(?:\s+(?<cmd>.+))?\s*$/ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Feels like this should be a const along with the other regex, and use the same capture group consts as well.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, doesn't this regex do the same as the const regex above? They seem to contain the same content.
| processId = parseInt(win32Match.groups.pid, 10); | ||
| parentProcessId = parseInt(win32Match.groups.ppid, 10); | ||
| } else { | ||
| // Legacy space-delimited listing: treat everything after pid as name, no command line |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this mean that process names can have spaces? Is that why tab-delimited was done later? Also, the regex used for the tab-delimited output seems to not actually care about tabs specifically, just whitespace, which seems to mean that the above regex should also work identically here (or that the above regex has an issue and would push the other segments of the space-containing process name into the command group)
| '-NoProfile', | ||
| '-Command', | ||
| `'PPID PID Name'; Get-CimInstance Win32_Process | % { '{0} {1} {2}' -f $_.ParentProcessId, $_.ProcessId, $_.Name }` | ||
| `'PPID\`tPID\`tName\`tCommandLine'; Get-CimInstance Win32_Process | % { '{0}\`t{1}\`t{2}\`t{3}' -f $_.ParentProcessId, $_.ProcessId, $_.Name, ($_.CommandLine -replace "\`t", " ") }` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| `'PPID\`tPID\`tName\`tCommandLine'; Get-CimInstance Win32_Process | % { '{0}\`t{1}\`t{2}\`t{3}' -f $_.ParentProcessId, $_.ProcessId, $_.Name, ($_.CommandLine -replace "\`t", " ") }` | |
| `"PPID\`0PID\`0Name\`0CommandLine"; Get-CimInstance Win32_Process | % { "{0}\`0{1}\`0{2}\`0{3}" -f $_.ParentProcessId, $_.ProcessId, $_.Name, $_.CommandLine }` |
Using NUL as the separator guarantees that it won't be encountered in any of the values. May need to run some tests though to figure out the right quoting to get them to be emitted when piping through the two translation layers, though
Summary
Introduce a
commandLineproperty toIProcessInfothat gets populated with the CLI that was passed into the process. In Node 24, the process name is set to "MainThread", so this restores some previous functionality from before Node 24.How it was tested
Introduced unit tests.
Impacted documentation
None.