From: ribes Date: Thu, 12 Nov 2009 14:54:18 +0000 (+0000) Subject: Command is now a script X-Git-Tag: new_launcher_alpha_091119~8 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=bde280419a5479bc13820e11e1918a3b052ee4bd;p=modules%2Fkernel.git Command is now a script --- diff --git a/src/Launcher/Launcher_Job_Command.cxx b/src/Launcher/Launcher_Job_Command.cxx index c66e0ec12..d288f1df4 100644 --- a/src/Launcher/Launcher_Job_Command.cxx +++ b/src/Launcher/Launcher_Job_Command.cxx @@ -58,11 +58,58 @@ Launcher::Job_Command::update_job() #ifdef WITH_LIBBATCH Batch::Parametre params = common_job_params(); - std::string command = ""; - if (_env_file != "") - command = "source " + _env_file + "\n"; - command += _command; - params[EXECUTABLE] = command; + // log + std::string log_file = "command.log"; + std::string log_local_file = _result_directory + "/" + log_file; + std::string log_remote_file = _work_directory + "/" + log_file; + params[OUTFILE] += Batch::Couple(log_local_file, log_remote_file); + + params[EXECUTABLE] = buildCommandScript(params); _batch_job->setParametre(params); #endif } + +#ifdef WITH_LIBBATCH +std::string +Launcher::Job_Command::buildCommandScript(Batch::Parametre params) +{ + // parameters + std::string work_directory = params[WORKDIR].str(); + + // File name + std::string::size_type p1 = _command.find_last_of("/"); + std::string::size_type p2 = _command.find_last_of("."); + std::string command_name = _command.substr(p1+1,p2-p1-1); + + time_t rawtime; + time(&rawtime); + std::string launch_date = ctime(&rawtime); + int i = 0 ; + for (;i < launch_date.size(); i++) + if (launch_date[i] == '/' or + launch_date[i] == '-' or + launch_date[i] == ':' or + launch_date[i] == ' ') + launch_date[i] = '_'; + launch_date.erase(--launch_date.end()); // Last caracter is a \n + + std::string launch_date_port_file = launch_date; + std::string launch_script = "/tmp/runCommand_" + command_name + "_" + launch_date + ".sh"; + std::ofstream launch_script_stream; + launch_script_stream.open(launch_script.c_str(), std::ofstream::out); + + // Script + launch_script_stream << "#! /bin/sh -f" << std::endl; + launch_script_stream << "cd " << work_directory << std::endl; + if (_env_file != "") + launch_script_stream << "source " << _env_file << std::endl; + launch_script_stream << _command << " > command.log 2>&1" << std::endl; + + // Return + launch_script_stream.flush(); + launch_script_stream.close(); + chmod(launch_script.c_str(), 0x1ED); + chmod(_command.c_str(), 0x1ED); + return launch_script; +} +#endif diff --git a/src/Launcher/Launcher_Job_Command.hxx b/src/Launcher/Launcher_Job_Command.hxx index c404af3aa..318c1db19 100644 --- a/src/Launcher/Launcher_Job_Command.hxx +++ b/src/Launcher/Launcher_Job_Command.hxx @@ -44,6 +44,11 @@ namespace Launcher virtual void update_job(); +#ifdef WITH_LIBBATCH + protected: + std::string buildCommandScript(Batch::Parametre params); +#endif + private: std::string _command; std::string _env_file; diff --git a/src/Launcher/Launcher_Job_YACSFile.cxx b/src/Launcher/Launcher_Job_YACSFile.cxx index 53f880b9c..be097b125 100644 --- a/src/Launcher/Launcher_Job_YACSFile.cxx +++ b/src/Launcher/Launcher_Job_YACSFile.cxx @@ -89,6 +89,7 @@ Launcher::Job_YACSFile::update_job() #endif } +#ifdef WITH_LIBBATCH std::string Launcher::Job_YACSFile::buildSalomeCouplingScript(Batch::Parametre params) { @@ -149,3 +150,4 @@ Launcher::Job_YACSFile::buildSalomeCouplingScript(Batch::Parametre params) chmod(launch_script.c_str(), 0x1ED); return launch_script; } +#endif