diff --git a/Source/build.cpp b/Source/build.cpp index cc15e245..c4ebb416 100644 --- a/Source/build.cpp +++ b/Source/build.cpp @@ -2191,7 +2191,7 @@ int CEXEBuild::pack_exe_header() } fwrite(m_exehead,1,m_exehead_size,tmpfile); fclose(tmpfile); - if (system(build_packcmd) == -1) + if (sane_system(build_packcmd) == -1) { remove(build_packname); ERROR_MSG("Error: calling packer on \"%s\"\n",build_packname); diff --git a/Source/script.cpp b/Source/script.cpp index 873f9d45..54db2d6b 100644 --- a/Source/script.cpp +++ b/Source/script.cpp @@ -2790,7 +2790,7 @@ int CEXEBuild::doCommand(int which_token, LineParser &line) if (!success && comp != 4) PRINTHELP() SCRIPT_MSG("!system: \"%s\"\n",exec); #ifdef _WIN32 - int ret=system(exec); + int ret=sane_system(exec); #else char *execfixed = my_convert(exec); int ret=system(execfixed); diff --git a/Source/util.cpp b/Source/util.cpp index 3a982917..c0a9bc66 100644 --- a/Source/util.cpp +++ b/Source/util.cpp @@ -692,3 +692,30 @@ string lowercase(const string &str) { transform(str.begin(), str.end(), result.begin(), tolower); return result; } + +int sane_system(const char *command) { +#ifdef _WIN32 + + // workaround for bug #1509909 + // http://sf.net/tracker/?func=detail&atid=373085&aid=1509909&group_id=22049 + // + // cmd.exe /C has some weird handling for quotes. it strips + // the surrounding quotes, if they exist. if there are quotes + // around the program path and its arguments, it will strip + // the outer quotes. this may result in something like: + // `program files\nsis\makensis.exe" "args` + // which obviously fails... + // + // to avoid the stripping, a harmless string is prefixed + // to the command line. + + string command_s = "IF 1==1 "; + command_s += command; + return system(command_s.c_str()); + +#else + + return system(command); + +#endif +} diff --git a/Source/util.h b/Source/util.h index e645fb2f..cc92214a 100644 --- a/Source/util.h +++ b/Source/util.h @@ -45,6 +45,8 @@ std::string lowercase(const std::string&); std::string get_string_prefix(const std::string& str, const std::string& separator); std::string get_string_suffix(const std::string& str, const std::string& separator); +int sane_system(const char *command); + #ifndef _WIN32 char *CharPrev(const char *s, const char *p); char *CharNext(const char *s);