@@ -297,18 +297,7 @@ func spawnExecutable(
297297 // unlikely to be deleted, one hopes).
298298 //
299299 // SEE: https://devblogs.microsoft.com/oldnewthing/20101109-00/?p=12323
300- var workingDirectoryPath = UnsafeMutableBufferPointer< wchar_t> . allocate( capacity: Int ( MAX_PATH) )
301- defer {
302- workingDirectoryPath. deallocate ( )
303- }
304- let systemDrive = Environment . variable ( named: " SYSTEMDRIVE " ) ?? " C: "
305- systemDrive. withCString ( encodedAs: UTF16 . self) { systemDrive in
306- wcscpy_s ( workingDirectoryPath. baseAddress!, workingDirectoryPath. count, systemDrive)
307- let rAddBackslash = PathCchAddBackslashEx ( workingDirectoryPath. baseAddress!, workingDirectoryPath. count, nil , nil )
308- guard rAddBackslash == S_OK || rAddBackslash == S_FALSE else {
309- fatalError ( " Unexpected error when normalizing system drive path ' \( systemDrive) ': HRESULT( \( rAddBackslash) ) " )
310- }
311- }
300+ let workingDirectoryPath = rootDirectoryPath
312301
313302 var flags = DWORD ( CREATE_NO_WINDOW | CREATE_UNICODE_ENVIRONMENT | EXTENDED_STARTUPINFO_PRESENT)
314303#if DEBUG
@@ -318,30 +307,32 @@ func spawnExecutable(
318307
319308 return try commandLine. withCString ( encodedAs: UTF16 . self) { commandLine in
320309 try environ. withCString ( encodedAs: UTF16 . self) { environ in
321- var processInfo = PROCESS_INFORMATION ( )
322-
323- guard CreateProcessW (
324- nil ,
325- . init( mutating: commandLine) ,
326- nil ,
327- nil ,
328- true , // bInheritHandles
329- flags,
330- . init( mutating: environ) ,
331- workingDirectoryPath,
332- startupInfo. pointer ( to: \. StartupInfo) !,
333- & processInfo
334- ) else {
335- throw Win32Error ( rawValue: GetLastError ( ) )
336- }
310+ try workingDirectoryPath. withCString ( encodedAs: UTF16 . self) { workingDirectoryPath in
311+ var processInfo = PROCESS_INFORMATION ( )
312+
313+ guard CreateProcessW (
314+ nil ,
315+ . init( mutating: commandLine) ,
316+ nil ,
317+ nil ,
318+ true , // bInheritHandles
319+ flags,
320+ . init( mutating: environ) ,
321+ workingDirectoryPath,
322+ startupInfo. pointer ( to: \. StartupInfo) !,
323+ & processInfo
324+ ) else {
325+ throw Win32Error ( rawValue: GetLastError ( ) )
326+ }
337327
338328#if DEBUG
339- // Resume the process.
340- _ = ResumeThread ( processInfo. hThread!)
329+ // Resume the process.
330+ _ = ResumeThread ( processInfo. hThread!)
341331#endif
342332
343- _ = CloseHandle ( processInfo. hThread)
344- return processInfo. hProcess!
333+ _ = CloseHandle ( processInfo. hThread)
334+ return processInfo. hProcess!
335+ }
345336 }
346337 }
347338 }
0 commit comments