Browse Source

[programming challenge] Paths with spaces work (win).

Michał W. Urbańczyk 14 years ago
parent
commit
c0637f333d
2 changed files with 16 additions and 5 deletions
  1. 15 4
      Odpalarka/main.cpp
  2. 1 1
      server/CVCMIServer.cpp

+ 15 - 4
Odpalarka/main.cpp

@@ -4,6 +4,14 @@
 #include <boost/program_options.hpp>
 namespace po = boost::program_options;
 
+std::string addQuotesIfNeeded(const std::string &s)
+{
+	if(s.find_first_of(' ') != std::string::npos)
+		return "\"" + s + "\"";
+
+	return s;
+}
+
 void prog_help() 
 {
 	std::cout << "If run without args, then StupidAI will be run on b1.json.\n";
@@ -15,7 +23,10 @@ void runCommand(const std::string &command, const std::string &name, const std::
 	static int i = 0;
 	std::string &cmd = commands[i++];
 	if(logsDir.size() && name.size())
-		cmd = command + " > " + logsDir + "/" + name + ".txt";
+	{
+		std::string directionLogs = logsDir + "/" + name + ".txt";
+		cmd = command + " > " + addQuotesIfNeeded(directionLogs);
+	}
 	else
 		cmd = command;
 
@@ -90,9 +101,9 @@ int main(int argc, char **argv)
 #endif
 	;
 
-	std::string serverCommand = servername + " " + battle + " " + leftAI + " " + rightAI + " " + results + " " + logsDir + " " + (withVisualization ? " v" : "");
-	std::string runnerCommand = runnername + " " + logsDir;
-	std::cout <<"Server command: " << serverCommand << std::endl << "Runner command: " << runnername << std::endl;
+	std::string serverCommand = servername + " " + addQuotesIfNeeded(battle) + " " + addQuotesIfNeeded(leftAI) + " " + addQuotesIfNeeded(rightAI) + " " + addQuotesIfNeeded(results) + " " + addQuotesIfNeeded(logsDir) + " " + (withVisualization ? " v" : "");
+	std::string runnerCommand = runnername + " " + addQuotesIfNeeded(logsDir);
+	std::cout <<"Server command: " << serverCommand << std::endl << "Runner command: " << runnerCommand << std::endl;
 
 	boost::thread t(boost::bind(std::system, serverCommand.c_str()));
 	runCommand(runnerCommand, "first_runner", logsDir);

+ 1 - 1
server/CVCMIServer.cpp

@@ -625,7 +625,7 @@ void CVCMIServer::startDuel(const std::string &battle, const std::string &leftAI
 		{
 			if(aisSoFar < 2)
 			{
-				tlog0 << " will run " << (aisSoFar ? "right" : "left") << " AI " << std::endl;
+				tlog0 << " (PID=" << pidsFromConns[c] << ") will run " << (aisSoFar ? "right" : "left") << " AI " << std::endl;
 				*c << gh->ais[aisSoFar] << ui8(aisSoFar);
 				PIDs[aisSoFar] = pidsFromConns[c];
 				aisSoFar++;