Salome HOME
typo-fix by Kunda
[modules/kernel.git] / src / Launcher / Launcher_Job_Command.cxx
index fd193e5211feb7ff892b8e3cdfb6e1517d96d1e6..ed4542bd11b6569bfeef01e1368d0279f7886e75 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2009-2015  CEA/DEN, EDF R&D, OPEN CASCADE
+// Copyright (C) 2009-2017  CEA/DEN, EDF R&D, OPEN CASCADE
 //
 // This library is free software; you can redistribute it and/or
 // modify it under the terms of the GNU Lesser General Public
 #define _chmod chmod
 #endif
 
-Launcher::Job_Command::Job_Command() {_job_type = "command";}
+#include <sstream>
+
+const char Launcher::Job_Command::TYPE_NAME[] = "command";
+
+Launcher::Job_Command::Job_Command()
+{
+  _job_type = Launcher::Job_Command::TYPE_NAME;
+}
 
 Launcher::Job_Command::~Job_Command() {}
 
@@ -46,7 +53,7 @@ Launcher::Job_Command::update_job()
 }
 
 #ifdef WITH_LIBBATCH
-std::string 
+std::string
 Launcher::Job_Command::buildCommandScript(Batch::Parametre params, std::string launch_date)
 {
   // parameters
@@ -54,10 +61,12 @@ Launcher::Job_Command::buildCommandScript(Batch::Parametre params, std::string l
 
   // File name
   std::string launch_date_port_file = launch_date;
-  std::string launch_script = Kernel_Utils::GetTmpDir() + "runCommand_" + _job_file_name + "_" + launch_date + ".sh";
+  std::ostringstream str_pid;
+  str_pid << ::getpid();
+  std::string launch_script = Kernel_Utils::GetTmpDir() + "runCommand_" + _job_file_name + "_" + launch_date + "-" + str_pid.str() + ".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;
@@ -68,7 +77,7 @@ Launcher::Job_Command::buildCommandScript(Batch::Parametre params, std::string l
     std::string::size_type last = _env_file.find_last_of("/");
     launch_script_stream << ". ./" << _env_file.substr(last+1) << std::endl;
   }
-  launch_script_stream << "./" << _job_file_name_complete << " > " << work_directory <<"/logs/command_" << launch_date << ".log 2>&1" << std::endl;
+  launch_script_stream << runCommandString() << std::endl;
 
   // Return
   launch_script_stream.flush();
@@ -77,4 +86,11 @@ Launcher::Job_Command::buildCommandScript(Batch::Parametre params, std::string l
   chmod(_job_file.c_str(), 0x1ED);
   return launch_script;
 }
+
+std::string Launcher::Job_Command::runCommandString()
+{
+  std::ostringstream result;
+  result << "./" << _job_file_name_complete;
+  return result.str();
+}
 #endif