File tree Expand file tree Collapse file tree 1 file changed +30
-1
lines changed
Expand file tree Collapse file tree 1 file changed +30
-1
lines changed Original file line number Diff line number Diff line change @@ -134,7 +134,36 @@ export async function listRunningProcesses(): Promise<Array<Proc>> {
134134
135135 return processes ;
136136 } else {
137- throw new Error ( "Windows not yet supported" ) ;
137+ const wmicOutput = await spawnToResult ( 'wmic' , [
138+ 'Process' , 'Get' , 'processid,commandline'
139+ ] ) ;
140+
141+ if ( wmicOutput . exitCode !== 0 ) {
142+ throw new Error ( `WMIC exited with unexpected error code ${ wmicOutput . exitCode } ` ) ;
143+ }
144+
145+ return getOutputLines ( wmicOutput . stdout )
146+ . slice ( 1 ) // Skip the header line
147+ . filter ( ( line ) => line . includes ( ' ' ) ) // Skip lines where the command line isn't available (just pids)
148+ . map ( ( line ) => {
149+ const pidIndex = line . lastIndexOf ( ' ' ) + 1 ;
150+ const pid = parseInt ( line . substring ( pidIndex ) , 10 ) ;
151+
152+ const command = line . substring ( 0 , pidIndex ) . trim ( ) ;
153+ const bin = command [ 0 ] === '"'
154+ ? command . substring ( 1 , command . substring ( 1 ) . indexOf ( '"' ) + 1 )
155+ : command . substring ( 0 , command . indexOf ( ' ' ) ) ;
156+ const args = command [ 0 ] === '"'
157+ ? command . substring ( bin . length + 3 )
158+ : command . substring ( bin . length + 1 ) ;
159+
160+ return {
161+ pid,
162+ command,
163+ bin,
164+ args
165+ } ;
166+ } ) ;
138167 }
139168}
140169
You can’t perform that action at this time.
0 commit comments