@@ -93,48 +93,37 @@ pub fn find_all_running_servers() -> Vec<RunningServer> {
9393 let mut running_servers = Vec :: new ( ) ;
9494
9595 if cfg ! ( target_os = "windows" ) {
96- // Use WMIC to get stackql processes with their command lines and PIDs
97- let output = ProcessCommand :: new ( "wmic " )
96+ // Use PowerShell Get-CimInstance to get stackql processes with command lines
97+ let output = ProcessCommand :: new ( "powershell " )
9898 . args ( [
99- "process" ,
100- "where" ,
101- "name='stackql.exe'" ,
102- "get" ,
103- "ProcessId,CommandLine" ,
104- "/format:list" ,
99+ "-NoProfile" ,
100+ "-Command" ,
101+ "Get-CimInstance Win32_Process -Filter \" Name='stackql.exe'\" | ForEach-Object { \" PID=$($_.ProcessId) CMD=$($_.CommandLine)\" }" ,
105102 ] )
106103 . output ( ) ;
107104
108105 if let Ok ( output) = output {
109106 let output_str = String :: from_utf8_lossy ( & output. stdout ) ;
110- let mut current_cmdline = String :: new ( ) ;
111- let mut current_pid: Option < u32 > = None ;
112-
113107 for line in output_str. lines ( ) {
114108 let line = line. trim ( ) ;
115- if let Some ( cmdline) = line. strip_prefix ( "CommandLine=" ) {
116- current_cmdline = cmdline. to_string ( ) ;
117- } else if let Some ( pid_str) = line. strip_prefix ( "ProcessId=" ) {
118- current_pid = pid_str. trim ( ) . parse ( ) . ok ( ) ;
119- }
120-
121- // When we have both values, emit a server entry
122- if let Some ( pid) = current_pid {
123- if !current_cmdline. is_empty ( ) {
124- if let Some ( port) = extract_port_from_cmdline ( & current_cmdline) {
125- debug ! (
126- "find_all_running_servers (Windows): PID {} -> port {} (cmdline: {})" ,
127- pid, port, current_cmdline
128- ) ;
129- running_servers. push ( RunningServer { pid, port } ) ;
109+ if let Some ( rest) = line. strip_prefix ( "PID=" ) {
110+ if let Some ( space_pos) = rest. find ( " CMD=" ) {
111+ let pid_str = & rest[ ..space_pos] ;
112+ let cmdline = & rest[ space_pos + 5 ..] ;
113+ if let Ok ( pid) = pid_str. parse :: < u32 > ( ) {
114+ if let Some ( port) = extract_port_from_cmdline ( cmdline) {
115+ debug ! (
116+ "find_all_running_servers (Windows): PID {} -> port {}" ,
117+ pid, port
118+ ) ;
119+ running_servers. push ( RunningServer { pid, port } ) ;
120+ }
130121 }
131- current_cmdline. clear ( ) ;
132- current_pid = None ;
133122 }
134123 }
135124 }
136125 } else {
137- debug ! ( "find_all_running_servers: wmic command failed, falling back to tasklist " ) ;
126+ debug ! ( "find_all_running_servers: PowerShell command failed" ) ;
138127 }
139128 } else {
140129 let output = ProcessCommand :: new ( "pgrep" )
0 commit comments