Skip to content

Commit

Permalink
Windows: convert the spawned command to locale encoding
Browse files Browse the repository at this point in the history
Converting to locale encoding is required to allows non-ASCII
characters in the command, e.g. in the file names.
  • Loading branch information
b4n committed Feb 19, 2014
1 parent 6af27ee commit 0ebf6ab
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/win32.c
Original file line number Diff line number Diff line change
Expand Up @@ -1038,6 +1038,7 @@ gboolean win32_spawn(const gchar *dir, gchar **argv, gchar **env, GSpawnFlags fl
gchar *tmp_file = create_temp_file();
gchar *tmp_errfile = create_temp_file();
gchar *command;
gchar *locale_command;

if (env != NULL)
{
Expand All @@ -1052,9 +1053,12 @@ gboolean win32_spawn(const gchar *dir, gchar **argv, gchar **env, GSpawnFlags fl
command = g_strjoinv(" ", argv);
SETPTR(command, g_strdup_printf("cmd.exe /S /C \"%s >%s 2>%s\"",
command, tmp_file, tmp_errfile));
locale_command = g_locale_from_utf8(command, -1, NULL, NULL, NULL);
if (! locale_command)
locale_command = g_strdup(command);
geany_debug("WIN32: actually running command:\n%s", command);
g_chdir(dir);
ret = system(command);
ret = system(locale_command);
/* the command can return -1 as an exit code, so check errno also */
fail = ret == -1 && errno;
if (!fail)
Expand All @@ -1068,6 +1072,7 @@ gboolean win32_spawn(const gchar *dir, gchar **argv, gchar **env, GSpawnFlags fl
g_set_error_literal(error, G_SPAWN_ERROR, errno, g_strerror(errno));

g_free(command);
g_free(locale_command);
g_unlink(tmp_file);
g_free(tmp_file);
g_unlink(tmp_errfile);
Expand Down

0 comments on commit 0ebf6ab

Please sign in to comment.