@@ -106,28 +106,41 @@ public static function getScriptPath(?int $pid = null): ?string
106106 }
107107
108108 if ($ os === 'WIN ' ) {
109- $ command = " powershell -NoProfile -Command \" (Get-CimInstance Win32_Process -Filter \\\" ProcessId=' $ pid ' \\\" ).CommandLine \" 2>&1 " ;
110- $ output = trim (( string ) shell_exec ( $ command )) ;
109+ $ command = ' powershell -NoProfile -Command '
110+ . ' "(Get-CimInstance Win32_Process -Filter \"ProcessId= ' . $ pid . ' \").CommandLine" 2>&1 ' ;
111111
112- if ($ output === '' ) {
112+ $ commandLine = trim ((string ) shell_exec ($ command ));
113+ if ($ commandLine === '' ) {
113114 return null ;
114115 }
115116
116- preg_match_all ('/"([^"]+)"|(\S+)/ ' , $ output , $ matches );
117- $ args = array_values (array_filter (array_merge ($ matches [1 ], $ matches [2 ])));
117+ // Parse Windows command line (handles quotes properly)
118+ preg_match_all ('/"([^"]+)"|(\S+)/u ' , $ commandLine , $ m );
119+ $ args = array_values (array_filter (array_merge ($ m [1 ], $ m [2 ])));
118120
119- foreach ($ args as $ arg ) {
120- if ($ arg [0 ] === '- ' ) {
121- continue ;
122- }
121+ // Remove php.exe
122+ array_shift ($ args );
123123
124- if (substr ($ arg , -4 ) !== '.php ' ) {
124+ // Get process working directory
125+ $ cwd = trim ((string ) shell_exec (
126+ 'powershell -NoProfile -Command '
127+ . '"(Get-CimInstance Win32_Process -Filter \"ProcessId= ' . $ pid . '\").WorkingDirectory" '
128+ ));
129+
130+ foreach ($ args as $ arg ) {
131+ if ($ arg === '' || $ arg [0 ] === '- ' ) {
125132 continue ;
126133 }
127134
135+ // Direct path
128136 if (is_file ($ arg )) {
129137 return realpath ($ arg );
130138 }
139+
140+ /// Relative path
141+ if ($ cwd && is_file ($ cwd . DIRECTORY_SEPARATOR . $ arg )) {
142+ return realpath ($ cwd . DIRECTORY_SEPARATOR . $ arg );
143+ }
131144 }
132145
133146 return null ;
0 commit comments