From ff52ec5410992eb0a7fb650714028a6f3b4f331f Mon Sep 17 00:00:00 2001 From: Sebastian Wehling-Benatelli Date: Mon, 22 Jun 2015 10:56:16 +0200 Subject: [PATCH] started implementation of running of external programs (work in progress, pending until release of picking window) --- pylot/core/util/utils.py | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/pylot/core/util/utils.py b/pylot/core/util/utils.py index 61b3fafc..0c8a863e 100644 --- a/pylot/core/util/utils.py +++ b/pylot/core/util/utils.py @@ -3,6 +3,7 @@ # -*- coding: utf-8 -*- import os +import subprocess import pwd import re import hashlib @@ -10,6 +11,27 @@ import numpy as np from obspy.core import UTCDateTime import obspy.core.event as ope +def runProgram(cmd, parameter=None): + """ + run an external program specified by cmd with parameters input returning the + stdout output + + :param cmd: name of the command to run + :type cmd: str + :param parameter: filename of parameter file or parameter string + :type parameter: str + :return: stdout output + :rtype: str + """ + + if parameter: + cmd.strip() + cmd += ' %s 2>&1' % parameter + + output = subprocess.check_output('{} | tee /dev/stderr'.format(cmd), + shell = True) + + def fnConstructor(s): if type(s) is str: