X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FLauncher%2FLauncher_Job_Command.cxx;h=eb86061b8cc58b0a151e574753f0f36c12d9ed30;hb=0f51fb65f0bb9dba3b9b686ed5bd7cc5a0e22229;hp=0fb681c35ec64b61bf012a48fe60a92699922afc;hpb=718e0abe0126e5e53b3ba41fff1028efcf5bc887;p=modules%2Fkernel.git diff --git a/src/Launcher/Launcher_Job_Command.cxx b/src/Launcher/Launcher_Job_Command.cxx index 0fb681c35..eb86061b8 100644 --- a/src/Launcher/Launcher_Job_Command.cxx +++ b/src/Launcher/Launcher_Job_Command.cxx @@ -1,4 +1,4 @@ -// Copyright (C) 2009-2016 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 @@ -29,9 +29,17 @@ #ifdef WIN32 #include #define _chmod chmod +#include #endif -Launcher::Job_Command::Job_Command() {_job_type = "command";} +#include + +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 +54,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,13 +62,29 @@ 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; +#ifdef WIN32 + str_pid << _getpid(); +#else + str_pid << ::getpid(); +#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 != "") @@ -68,7 +92,22 @@ 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; +#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(); @@ -77,4 +116,15 @@ 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; +#ifndef WIN32 + result << "./" << _job_file_name_complete; +#else + result << "call " << _job_file_name_complete; +#endif + return result.str(); +} #endif