]> SALOME platform Git repositories - modules/kernel.git/commitdiff
Salome HOME
Command is now a script
authorribes <ribes>
Thu, 12 Nov 2009 14:54:18 +0000 (14:54 +0000)
committerribes <ribes>
Thu, 12 Nov 2009 14:54:18 +0000 (14:54 +0000)
src/Launcher/Launcher_Job_Command.cxx
src/Launcher/Launcher_Job_Command.hxx
src/Launcher/Launcher_Job_YACSFile.cxx

index c66e0ec12fd1dc6e2db04461942ea4147b5a4bb5..d288f1df44264306890ef0ac37195711838eb10e 100644 (file)
@@ -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
index c404af3aa77e6057fdb2c4609c5c7a1fe4e9026f..318c1db19830e3890acfc3e4884d8cd1417800e3 100644 (file)
@@ -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;
index 53f880b9c47de5d3f75af62058ea4e4dcc54891e..be097b125167794bd69d1bb3639d7ec41a2f5078 100644 (file)
@@ -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