Index: process/src/com/zorba-xquery/www/modules/process.xq.src/process.cpp =================================================================== --- process/src/com/zorba-xquery/www/modules/process.xq.src/process.cpp (revision 12133) +++ process/src/com/zorba-xquery/www/modules/process.xq.src/process.cpp (working copy) @@ -374,52 +374,65 @@ lCommand = getOneStringArgument(aArgs, 0).c_str(); + // if we have command arguments if (aArgs.size() > 1) { zorba::Item lArg; - Iterator_t arg1_iter = aArgs[1]->getIterator(); - arg1_iter->open(); - while (arg1_iter->next(lArg)) + Iterator_t lArgIter = aArgs[1]->getIterator(); + lArgIter->open(); + while (lArgIter->next(lArg)) { lArgs.push_back(lArg.getStringValue().c_str()); } - arg1_iter->close(); + lArgIter->close(); } std::ostringstream lTmp; #ifdef WIN32 - // execute process command in a new commandline - // with quotes at the beggining and at the end - lTmp << "cmd /C \""; + // run a command with cmd (the command in the string following /C + // will not have the quotes changed because of /S + // + // begin the command string + lTmp << "cmd /S /C \""; #endif - - lTmp << "\"" << lCommand << "\""; //quoted for spaced paths/filenames - size_t pos=0; + +#ifdef WIN32 + // surround the command with quoted - begin + lTmp << "\""; +#endif + + lTmp << lCommand; + +#ifdef WIN32 + // surround the command with quoted - end + lTmp << "\""; +#endif + + std::size_t lPos = 0; for (std::vector::const_iterator lIter = lArgs.begin(); lIter != lArgs.end(); ++lIter) { - pos = (*lIter).rfind('\\')+(*lIter).rfind('/'); - if (int(pos)>=0) - lTmp << " \"" << *lIter << "\""; - else - lTmp << " " << *lIter; + lTmp << " \"" << *lIter << "\""; } + #ifdef WIN32 - lTmp << "\""; // with quotes at the end for commandline + // end the command string + lTmp << "\""; #endif std::ostringstream lStdout; std::ostringstream lStderr; #ifdef WIN32 - std::string lCommandLineString=lTmp.str(); - int code = run_process(lCommandLineString,lStdout,lStderr); + std::string lCommandLineString = lTmp.str(); + int code = run_process(lCommandLineString, lStdout, lStderr); if (code != 0) { std::stringstream lErrorMsg; - lErrorMsg << "Failed to execute the command (" << code << ")"; + lErrorMsg << "Failed to execute the command: " << lCommandLineString << std::endl + << "Error: " << lStderr.str() << std::endl; Item lQName = ProcessModule::getItemFactory()->createQName( "http://www.zorba-xquery.com/modules/process", "PROC01"); throw USER_EXCEPTION(lQName, lErrorMsg.str().c_str());