-// Copyright (C) 2009-2017 CEA/DEN, EDF R&D, OPEN CASCADE
+// Copyright (C) 2009-2021 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
#ifdef WIN32
#include <io.h>
#define _chmod chmod
+#include <process.h>
#endif
#include <sstream>
-Launcher::Job_Command::Job_Command() {_job_type = "command";}
+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() {}
// File name
std::string launch_date_port_file = launch_date;
std::ostringstream str_pid;
+#ifdef WIN32
+ str_pid << _getpid();
+#else
str_pid << ::getpid();
- std::string launch_script = Kernel_Utils::GetTmpDir() + "runCommand_" + _job_file_name + "_" + launch_date + "-" + str_pid.str() + ".sh";
+#endif
+ std::string launch_script = Kernel_Utils::GetTmpDir() + "runCommand_"
+ + _job_file_name + "_" + launch_date + "-"
+ + str_pid.str();
+#ifndef WIN32
+ launch_script += ".sh";
+#else
+ launch_script += ".bat";
+#endif
std::ofstream launch_script_stream;
launch_script_stream.open(launch_script.c_str(), std::ofstream::out);
// Script
+#ifndef WIN32
launch_script_stream << "#!/bin/sh -f" << std::endl;
launch_script_stream << "cd " << work_directory << std::endl;
+ // remove the exit code from any previous execution
+ launch_script_stream << "rm -f logs/exit_code.log" << std::endl;
launch_script_stream << "export PYTHONPATH=" << work_directory << ":$PYTHONPATH" << std::endl;
launch_script_stream << "export PATH=" << work_directory << ":$PATH" << std::endl;
if (_env_file != "")
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 << std::endl;
+#else
+ launch_script_stream << "echo OFF" << std::endl;
+ launch_script_stream << "cd " << work_directory << std::endl;
+ launch_script_stream << "set PYTHONPATH=" << work_directory << ";%PYTHONPATH%" << std::endl;
+ launch_script_stream << "set PATH=" << work_directory << ";%PATH%" << std::endl;
+ if (_env_file != "")
+ {
+ std::string::size_type last = _env_file.find_last_of("\\");
+ launch_script_stream << "call " << _env_file.substr(last+1) << std::endl;
+ }
+#endif
+ launch_script_stream << runCommandString() << std::endl;
+#ifndef WIN32
+ // log the exit code
+ launch_script_stream << "echo $? > logs/exit_code.log" << std::endl;
+#endif
// Return
launch_script_stream.flush();
chmod(_job_file.c_str(), 0x1ED);
return launch_script;
}
+
+std::string Launcher::Job_Command::runCommandString()
+{
+ std::ostringstream result;
+#ifndef WIN32
+ result << "./" << _job_file_name_complete;
+#else
+ result << "call " << _job_file_name_complete;
+#endif
+ return result.str();
+}
#endif