@@ -257,6 +257,18 @@ static WCHAR *prep_env(char **envp) {
257257 return NULL ;
258258}
259259
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+
260272static bool conpty_setup (HPCON * hnd , COORD size , STARTUPINFOEXW * si_ex , char * * in_name , char * * out_name ) {
261273 static int count = 0 ;
262274 char buf [256 ];
@@ -361,13 +373,17 @@ int pty_spawn(pty_process *process, pty_read_cb read_cb, pty_exit_cb exit_cb) {
361373 uv_pipe_connect (out_req , io -> out , out_name , connect_cb );
362374
363375 PROCESS_INFORMATION pi = {0 };
364- WCHAR * cmdline , * env ;
376+ WCHAR * cmdline , * env , * cwd ;
365377 cmdline = join_args (process -> argv );
366378 if (cmdline == NULL ) goto cleanup ;
367379 env = prep_env (process -> envp );
368380 if (env == NULL ) goto cleanup ;
381+ if (process -> cwd != NULL ) {
382+ cwd = to_utf16 (process -> cwd );
383+ if (cwd == NULL ) goto cleanup ;
384+ }
369385
370- if (!CreateProcessW (NULL , cmdline , NULL , NULL , FALSE, flags , env , process -> cwd , & process -> si .StartupInfo , & pi )) {
386+ if (!CreateProcessW (NULL , cmdline , NULL , NULL , FALSE, flags , env , cwd , & process -> si .StartupInfo , & pi )) {
371387 print_error ("CreateProcessW" );
372388 goto cleanup ;
373389 }
@@ -392,6 +408,7 @@ int pty_spawn(pty_process *process, pty_read_cb read_cb, pty_exit_cb exit_cb) {
392408 if (out_name != NULL ) free (out_name );
393409 if (cmdline != NULL ) free (cmdline );
394410 if (env != NULL ) free (env );
411+ if (cwd != NULL ) free (cwd );
395412 return status ;
396413}
397414#else
0 commit comments