Repository: lucy Updated Branches: refs/heads/master 70caaa3d3 -> 6f1efa315
Regenerate charmonizer.c for Windows fix Project: http://git-wip-us.apache.org/repos/asf/lucy/repo Commit: http://git-wip-us.apache.org/repos/asf/lucy/commit/6f1efa31 Tree: http://git-wip-us.apache.org/repos/asf/lucy/tree/6f1efa31 Diff: http://git-wip-us.apache.org/repos/asf/lucy/diff/6f1efa31 Branch: refs/heads/master Commit: 6f1efa315e36f7814988c7c7a5fa11fb27c433bd Parents: 70caaa3 Author: Nick Wellnhofer <wellnho...@aevum.de> Authored: Thu Jun 30 18:39:42 2016 +0200 Committer: Nick Wellnhofer <wellnho...@aevum.de> Committed: Thu Jun 30 18:40:10 2016 +0200 ---------------------------------------------------------------------- common/charmonizer.c | 37 ++++++++++++++++++------------------- 1 file changed, 18 insertions(+), 19 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/lucy/blob/6f1efa31/common/charmonizer.c ---------------------------------------------------------------------- diff --git a/common/charmonizer.c b/common/charmonizer.c index 633ab34..37d0a92 100644 --- a/common/charmonizer.c +++ b/common/charmonizer.c @@ -5456,7 +5456,7 @@ static struct { } chaz_OS = { "", "", "", "", 0, 0 }; static int -chaz_OS_run_sh_via_cmd_exe(const char *command); +chaz_OS_run_sh_via_cmd_exe(const char *command, const char *path); void chaz_OS_init(void) { @@ -5615,6 +5615,9 @@ int chaz_OS_run_redirected(const char *command, const char *path) { int retval = 1; char *quiet_command = NULL; + if (chaz_OS.run_sh_via_cmd_exe) { + return chaz_OS_run_sh_via_cmd_exe(command, path); + } if (chaz_OS.shell_type == CHAZ_OS_POSIX || chaz_OS.shell_type == CHAZ_OS_CMD_EXE ) { @@ -5623,27 +5626,23 @@ chaz_OS_run_redirected(const char *command, const char *path) { else { chaz_Util_die("Don't know the shell type"); } - if (chaz_OS.run_sh_via_cmd_exe) { - retval = chaz_OS_run_sh_via_cmd_exe(quiet_command); - } - else { - retval = system(quiet_command); - } + retval = system(quiet_command); free(quiet_command); return retval; } static int -chaz_OS_run_sh_via_cmd_exe(const char *command) { +chaz_OS_run_sh_via_cmd_exe(const char *command, const char *path) { size_t i; size_t size; - char *sh_command; + char *escaped_command; + char *wrapped_command; char *p; int retval; /* Compute size. */ - size = sizeof("sh -c \"\""); + size = 0; for (i = 0; command[i] != '\0'; i++) { char c = command[i]; @@ -5667,10 +5666,8 @@ chaz_OS_run_sh_via_cmd_exe(const char *command) { /* Build sh command. */ - sh_command = (char*)malloc(size); - p = sh_command; - memcpy(p, "sh -c \"", 7); - p += 7; + escaped_command = (char*)malloc(size + 1); + p = escaped_command; /* Escape special characters. */ @@ -5700,14 +5697,16 @@ chaz_OS_run_sh_via_cmd_exe(const char *command) { } } - /* Finish and run sh command. */ - - *p++ = '"'; *p++ = '\0'; - retval = system(sh_command); + /* Run sh command. */ + + wrapped_command = chaz_Util_join("", "sh -c \"", escaped_command, "\" > ", + path, " 2>&1", NULL); + retval = system(wrapped_command); - free(sh_command); + free(wrapped_command); + free(escaped_command); return retval; }