Skip to content

Commit 6411b81

Browse files
authored
Merge pull request #2261 from compnerd/give-the-environment-a-train
Process: correct environment block handling on Windows
2 parents cb7e86b + 6f00f7d commit 6411b81

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

Foundation/Process.swift

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -445,7 +445,10 @@ open class Process: NSObject {
445445
environment["PWD"] = currentDirectoryURL.path
446446
}
447447

448-
let szEnvironment: String = environment.map { $0.key + "=" + $0.value }.joined(separator: "\0")
448+
// NOTE(compnerd) the environment string must be terminated by a double
449+
// null-terminator. Otherwise, CreateProcess will fail with
450+
// INVALID_PARMETER.
451+
let szEnvironment: String = environment.map { $0.key + "=" + $0.value }.joined(separator: "\0") + "\0\0"
449452

450453
let sockets: (first: SOCKET, second: SOCKET) = _socketpair()
451454

0 commit comments

Comments
 (0)