Salome HOME
Removing -s option for run
[modules/hydrosolver.git] / src / salome_hydro / run_study / launcher.py
index 3702551024ca279aa0620bc5747a600e5ecad2fd..efeb88c41e74464e23ff3388d4ef6b7d710b54bb 100644 (file)
@@ -14,6 +14,9 @@
 #
 #  You should have received a copy of the GNU General Public License
 #  along with SALOME HYDRO module.  If not, see <http://www.gnu.org/licenses/>.
+"""
+Script for launch in terminal of a steering file
+"""
 
 import os
 import subprocess
@@ -47,26 +50,26 @@ def run_study(param_dict):
     orig_steering = f.read()
   orig_steering_lines = orig_steering.split("\n")
 
-  cmd = "set -x ; "
 
   # Run the code itself
   code = param_dict["CODE"]
-  cmd += "runcode.py -w %s %s %s" % \
-         (wrkdir, code, steering_filepath)
-  cmd += " ; rc=$?"
+  cmd = "runcode.py {code} -w {wrkdir} {steering_filepath} " \
+         .format(code=code,
+                 wrkdir=wrkdir,
+                 steering_filepath=os.path.basename(steering_filepath))
 
-  # Cleanup intermediate files if the computation was successful
-  cmd += " ; if test $rc -eq 0; then rm -rf %s ; fi" % " ".join(interm_files)
+  # Launch the command
+  logger.debug("Running the following command in salome shell in %s: %s", steering_file_dir, cmd)
+  try:
+      log = subprocess.check_output(cmd, cwd=steering_file_dir, stderr=subprocess.STDOUT, shell=True)
+      passed = True
+      log = log.decode('utf-8')
+  except subprocess.CalledProcessError as e:
+      passed = False
+      log = str(e)+"\n"+e.output.decode('utf-8')
 
-  cmd += ' ; echo "return code is $rc"'
+  return passed, log
 
-  # Launch the command
-  logger.debug("Running the following command in xterm: %s" % cmd)
-  args = ["xterm", "-T", "Execution of Telemac", "-geo", "80x60", "-hold", "-l", "-e", cmd]
-  if param_dict.has_key('batchExec'):
-    if param_dict['batchExec'] == True:
-      args = ["xterm", "-T", "Execution of Telemac", "-geo", "80x60", "+hold", "-l", "-e", cmd]
-  subprocess.Popen(args, cwd = wrkdir)
 
 def check_file_or_create_link(filepath, dirpath, interm_file_list = None):
   """