refs #1059 add ogGetCaller()
parent
9301d9aaaf
commit
94813cea3c
|
@ -117,16 +117,33 @@ def ogExecAndLog(*args):
|
||||||
# Salida de error del comando ejecutado.
|
# Salida de error del comando ejecutado.
|
||||||
return subprocess.PIPESTATUS[0]
|
return subprocess.PIPESTATUS[0]
|
||||||
|
|
||||||
|
#/**
|
||||||
|
# ogGetCaller
|
||||||
|
#@brief Devuelve nombre del programa o script ejecutor (padre).
|
||||||
|
#@return str_name - Nombre del programa ejecutor.
|
||||||
|
#*/
|
||||||
def ogGetCaller():
|
def ogGetCaller():
|
||||||
# Obtener el nombre del programa o del script que ha llamado al proceso actual.
|
if 'COLUMNS' in os.environ:
|
||||||
output = subprocess.check_output(["ps", "hp", str(os.getppid()), "-o", "args"]).decode("utf-8")
|
cols = os.environ['COLUMNS']
|
||||||
lines = output.split("\n")
|
|
||||||
caller = ""
|
|
||||||
for line in lines:
|
|
||||||
if "bash" in line and line.split()[1] != "":
|
|
||||||
caller = line.split()[1]
|
|
||||||
else:
|
else:
|
||||||
caller = line.split()[0].lstrip("-")
|
cols = None
|
||||||
|
|
||||||
|
lines = subprocess.run (["ps", "hp", str(os.getppid()), "-o", "args"], capture_output=True, text=True).stdout.splitlines()
|
||||||
|
if 0 == len (lines):
|
||||||
|
return ''
|
||||||
|
|
||||||
|
line = lines[0]
|
||||||
|
words = line.split()
|
||||||
|
if "bash" in line and len(words)>1:
|
||||||
|
caller = words[1]
|
||||||
|
else:
|
||||||
|
caller = words[0].lstrip("-")
|
||||||
|
|
||||||
|
if cols is None:
|
||||||
|
del (os.environ['COLUMNS'])
|
||||||
|
else:
|
||||||
|
os.environ['COLUMNS'] = cols
|
||||||
|
|
||||||
return os.path.basename(caller)
|
return os.path.basename(caller)
|
||||||
|
|
||||||
def ogHelp(*args):
|
def ogHelp(*args):
|
||||||
|
|
Loading…
Reference in New Issue