From 6363bf9eb5dd00bdabf7a911240cd287fe7bf6ec Mon Sep 17 00:00:00 2001 From: Jeremy Schonfeld Date: Mon, 1 Jul 2024 15:44:54 -0700 Subject: [PATCH 1/2] Use FSR for Process executable path on Windows --- Sources/Foundation/Process.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sources/Foundation/Process.swift b/Sources/Foundation/Process.swift index 0f32045e49..622d388b37 100644 --- a/Sources/Foundation/Process.swift +++ b/Sources/Foundation/Process.swift @@ -499,7 +499,7 @@ open class Process: NSObject { } #if os(Windows) - var command: [String] = [launchPath] + var command: [String] = [try FileManager.default._fileSystemRepresentation(withPath: launchPath) { String(decodingCString: $0, as: UTF16.self) }] if let arguments = self.arguments { command.append(contentsOf: arguments) } From f4dbb1803f06683f27719574a918e390dfdbafc1 Mon Sep 17 00:00:00 2001 From: Jeremy Schonfeld Date: Mon, 1 Jul 2024 16:15:56 -0700 Subject: [PATCH 2/2] Use FSR on Linux as well --- Sources/Foundation/Process.swift | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/Sources/Foundation/Process.swift b/Sources/Foundation/Process.swift index 622d388b37..76aeed1b4c 100644 --- a/Sources/Foundation/Process.swift +++ b/Sources/Foundation/Process.swift @@ -958,9 +958,12 @@ open class Process: NSObject { // Launch var pid = pid_t() - guard _CFPosixSpawn(&pid, launchPath, fileActions, &spawnAttrs, argv, envp) == 0 else { - throw _NSErrorWithErrno(errno, reading: true, path: launchPath) - } + + try FileManager.default._fileSystemRepresentation(withPath: launchPath, { fsRep in + guard _CFPosixSpawn(&pid, fsRep, fileActions, &spawnAttrs, argv, envp) == 0 else { + throw _NSErrorWithErrno(errno, reading: true, path: launchPath) + } + }) posix_spawnattr_destroy(&spawnAttrs) // Close the write end of the input and output pipes.