diff --git a/Source/cmExecProgramCommand.cxx b/Source/cmExecProgramCommand.cxx index b6159eada..66e0cd6f0 100644 --- a/Source/cmExecProgramCommand.cxx +++ b/Source/cmExecProgramCommand.cxx @@ -88,7 +88,7 @@ bool cmExecProgramCommand::InitialPass(std::vector const& args) std::string command; if(arguments.size()) { - command = cmSystemTools::ConvertToOutputPath(args[0].c_str()); + command = cmSystemTools::ConvertToRunCommandPath(args[0].c_str()); command += " "; command += arguments; } @@ -103,15 +103,16 @@ bool cmExecProgramCommand::InitialPass(std::vector const& args) } int retVal = 0; std::string output; + bool result = true; if(args.size() - count == 2) { cmSystemTools::MakeDirectory(args[1].c_str()); - cmSystemTools::RunCommand(command.c_str(), output, retVal, - cmSystemTools::ConvertToOutputPath(args[1].c_str()).c_str(), verbose); + result = cmSystemTools::RunCommand(command.c_str(), output, retVal, + args[1].c_str(), verbose); } else { - cmSystemTools::RunCommand(command.c_str(), output, retVal, 0, verbose); + result = cmSystemTools::RunCommand(command.c_str(), output, retVal, 0, verbose); } if ( output_variable.size() > 0 ) @@ -138,6 +139,6 @@ bool cmExecProgramCommand::InitialPass(std::vector const& args) m_Makefile->AddDefinition(return_variable.c_str(), buffer); } - return true; + return result; } diff --git a/Source/cmSystemTools.cxx b/Source/cmSystemTools.cxx index 9fc00609b..5c1d5af85 100644 --- a/Source/cmSystemTools.cxx +++ b/Source/cmSystemTools.cxx @@ -573,7 +573,6 @@ bool RunCommandViaWin32(const char* command, cmSystemTools::Error("No command specified"); return false; } - cmWin32ProcessExecution resProc; if(cmSystemTools::GetRunCommandHideConsole()) { @@ -586,6 +585,11 @@ bool RunCommandViaWin32(const char* command, } if ( !resProc.StartProcess(command, dir, verbose) ) { + output = resProc.GetOutput(); + if(verbose) + { + cmSystemTools::Stdout(output.c_str()); + } return false; } resProc.Wait(timeout); @@ -1148,6 +1152,15 @@ std::string cmSystemTools::ConvertToOutputPath(const char* path) #endif } +std::string cmSystemTools::ConvertToRunCommandPath(const char* path) +{ +#if defined(_WIN32) && !defined(__CYGWIN__) + return cmSystemTools::ConvertToWindowsOutputPath(path); +#else + return cmSystemTools::ConvertToUnixOutputPath(path); +#endif +} + bool cmSystemTools::StringEndsWith(const char* str1, const char* str2) { if ( !str1 || !str2 || strlen(str1) < strlen(str2) ) diff --git a/Source/cmSystemTools.h b/Source/cmSystemTools.h index 286240636..f779ecccb 100644 --- a/Source/cmSystemTools.h +++ b/Source/cmSystemTools.h @@ -252,7 +252,12 @@ public: { s_ForceUnixPaths = v; } + // ConvertToOutputPath use s_ForceUnixPaths static std::string ConvertToOutputPath(const char* path); + // ConvertToRunCommandPath does not use s_ForceUnixPaths and should + // be used when RunCommand is called from cmake, because the + // running cmake needs paths to be in its format + static std::string ConvertToRunCommandPath(const char* path); //! Check if the first string ends with the second one. static bool StringEndsWith(const char* str1, const char* str2); diff --git a/Source/cmTryRunCommand.cxx b/Source/cmTryRunCommand.cxx index f8c039e13..b7300c820 100644 --- a/Source/cmTryRunCommand.cxx +++ b/Source/cmTryRunCommand.cxx @@ -94,7 +94,7 @@ bool cmTryRunCommand::InitialPass(std::vector const& argv) if (fullPath.size() > 1) { std::string finalCommand = fullPath; - finalCommand = cmSystemTools::ConvertToOutputPath(fullPath.c_str()); + finalCommand = cmSystemTools::ConvertToRunCommandPath(fullPath.c_str()); if(runArgs.size()) { finalCommand += runArgs; diff --git a/Source/cmWin32ProcessExecution.cxx b/Source/cmWin32ProcessExecution.cxx index ba736dba4..d06a33cae 100644 --- a/Source/cmWin32ProcessExecution.cxx +++ b/Source/cmWin32ProcessExecution.cxx @@ -441,9 +441,37 @@ static BOOL RealPopenCreateProcess(const char *cmdstring, free(s1); return TRUE; } - output += "CreateProcessError "; - output += s2; + + LPVOID lpMsgBuf; + + FormatMessage( + FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM, + NULL, + GetLastError(), + MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language + (LPTSTR) &lpMsgBuf, + 0, + NULL + ); + + // Free the buffer. + + char* str = 0; + str = strcpy(new char[strlen((char*)lpMsgBuf)+1], (char*)lpMsgBuf); + LocalFree( lpMsgBuf ); + + output += "CreateProcessError: "; + output += str; output += "\n"; + output += "for command: "; + output += s2; + if(path) + { + output += "\nin dir: "; + output += path; + } + output += "\n"; + delete [] str; free(s2); free(s1); return FALSE;