X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=bin%2FrunSession.py;h=f698e323d252914a436b0cbc298a2c3cbb9d49b8;hb=3091a8beac430b5b36c7606fc672dcf869a8683d;hp=bd2256b0b65ec1fae430b18fe97e20c5ba2cade6;hpb=d4617a5edb41e7acd4025a2b56160ae267ede7f6;p=modules%2Fkernel.git diff --git a/bin/runSession.py b/bin/runSession.py index bd2256b0b..f698e323d 100644 --- a/bin/runSession.py +++ b/bin/runSession.py @@ -26,6 +26,7 @@ import sys from optparse import OptionParser from NSparam import getNSparams import socket +import subprocess # Use to display newlines (\n) in epilog class MyParser(OptionParser): @@ -33,7 +34,9 @@ class MyParser(OptionParser): return self.epilog # -def configureSession(args=[]): +def configureSession(args=None): + if args is None: + args = [] usage = "Usage: %prog [options] [command]" epilog = """\n If the command is not given a shell is opened; else execute the given command. @@ -104,3 +107,40 @@ def _writeConfigFile(port, host): os.environ['OMNIORB_CONFIG'] = filename # + +# command looks like a Bash command-line: +# script1.py [args] ; script2.py [args] ; ... +def runSession(command): + if command: + sep = ";" + if sys.platform == "win32": + sep= "&" + command = command.split(sep) + outmsg = [] + errmsg = [] + for cmd in command: + save_cmd = cmd + cmd = cmd.strip().split(' ') + #proc = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE) + proc = subprocess.Popen(cmd) + (stdoutdata, stderrdata) = proc.communicate() + if stdoutdata: + outmsg.append(stdoutdata) + if stderrdata: + errmsg.append(stderrdata) + + if proc.returncode != 0: + errmsg.append("Error raised when executing command: %s\n"%save_cmd) + if outmsg: + sys.stdout.write("".join(outmsg)) + if errmsg: + sys.stderr.write("".join(errmsg)) + sys.exit(proc.returncode) + + return ("".join(outmsg), "".join(errmsg)) + else: + absoluteAppliPath = os.getenv('ABSOLUTE_APPLI_PATH','') + cmd = ["/bin/bash", "--rcfile", absoluteAppliPath + "/.bashrc" ] + proc = subprocess.Popen(cmd, shell=False, close_fds=True) + return proc.communicate() +#