@@ -257,6 +257,18 @@ static WCHAR *prep_env(char **envp) {
257
257
return NULL ;
258
258
}
259
259
260
+ static WCHAR * to_utf16 (char * str ) {
261
+ int len = MultiByteToWideChar (CP_UTF8 , 0 , str , -1 , NULL , 0 );
262
+ if (len <= 0 ) return NULL ;
263
+ WCHAR * wstr = xmalloc ((len + 1 ) * sizeof (WCHAR ));
264
+ if (len != MultiByteToWideChar (CP_UTF8 , 0 , str , -1 , wstr , len )) {
265
+ free (wstr );
266
+ return NULL ;
267
+ }
268
+ wstr [len ] = L'\0' ;
269
+ return wstr ;
270
+ }
271
+
260
272
static bool conpty_setup (HPCON * hnd , COORD size , STARTUPINFOEXW * si_ex , char * * in_name , char * * out_name ) {
261
273
static int count = 0 ;
262
274
char buf [256 ];
@@ -361,13 +373,15 @@ int pty_spawn(pty_process *process, pty_read_cb read_cb, pty_exit_cb exit_cb) {
361
373
uv_pipe_connect (out_req , io -> out , out_name , connect_cb );
362
374
363
375
PROCESS_INFORMATION pi = {0 };
364
- WCHAR * cmdline , * env ;
376
+ WCHAR * cmdline , * env , * cwd ;
365
377
cmdline = join_args (process -> argv );
366
378
if (cmdline == NULL ) goto cleanup ;
367
379
env = prep_env (process -> envp );
368
380
if (env == NULL ) goto cleanup ;
381
+ cwd = to_utf16 (process -> cwd );
382
+ if (cwd == NULL ) goto cleanup ;
369
383
370
- if (!CreateProcessW (NULL , cmdline , NULL , NULL , FALSE, flags , env , process -> cwd , & process -> si .StartupInfo , & pi )) {
384
+ if (!CreateProcessW (NULL , cmdline , NULL , NULL , FALSE, flags , env , cwd , & process -> si .StartupInfo , & pi )) {
371
385
print_error ("CreateProcessW" );
372
386
goto cleanup ;
373
387
}
@@ -392,6 +406,7 @@ int pty_spawn(pty_process *process, pty_read_cb read_cb, pty_exit_cb exit_cb) {
392
406
if (out_name != NULL ) free (out_name );
393
407
if (cmdline != NULL ) free (cmdline );
394
408
if (env != NULL ) free (env );
409
+ if (cwd != NULL ) free (cwd );
395
410
return status ;
396
411
}
397
412
#else
0 commit comments