@@ -14,6 +14,7 @@ import var Foundation.NSLocalizedDescriptionKey
14
14
15
15
#if os(Windows)
16
16
import Foundation
17
+ import WinSDK. core. sysinfo
17
18
#endif
18
19
19
20
@_implementationOnly import TSCclibc
@@ -350,11 +351,32 @@ public final class Process {
350
351
pathString: ProcessEnv . path,
351
352
currentWorkingDirectory: cwdOpt
352
353
)
354
+ #if os(Windows)
355
+ var searchPaths = [ String] ( )
356
+ let buffer = UnsafeMutablePointer< String> . allocate( capacity: 260 )
357
+
358
+ // The 32-bit Windows system directory
359
+ GetSystemDirectoryW ( buffer, 260 )
360
+ searchPaths += buffer. pointee
361
+
362
+ // The 16-bit Windows system directory
363
+ searchPaths += " \( ProcessEnv . vars [ " systemdrive " ] ?? " C: " ) \\ System "
364
+
365
+ // The Windows directory
366
+ GetWindowsDirectoryW ( buffer, 260 )
367
+ searchPaths += buffer. pointee
368
+
369
+ searchPaths. append ( contentsOf: envSearchPaths)
370
+ #else
371
+ let searchPaths = envSearchPaths
372
+ #endif
373
+ // Lookup and cache the executable path.
353
374
let value = lookupExecutablePath (
354
375
filename: program,
355
376
currentWorkingDirectory: cwdOpt,
356
- searchPaths: envSearchPaths
377
+ searchPaths: searchPaths
357
378
)
379
+ Process . validatedExecutablesMap [ program] = value
358
380
return value
359
381
}
360
382
// This should cover the most common cases, i.e. when the cache is most helpful.
0 commit comments