Did I find the right examples for you? yes no      Crawl my project      Python Jobs

All Samples(2)  |  Call(1)  |  Derive(0)  |  Import(1)
Call terminal command and return exit_code and stdout

Parameters
----------
args : list
    A command and arguments list

Returns
-------
list : [exit_code, stdout](more...)

        def call(args):
    """
    Call terminal command and return exit_code and stdout

    Parameters
    ----------
    args : list
        A command and arguments list

    Returns
    -------
    list : [exit_code, stdout]
        exit_code indicate the exit code of the command and stdout indicate the
        output of the command
    """
    b = StringIO()
    p = subprocess.Popen(args,
                        stdout=subprocess.PIPE,
                        stderr=subprocess.STDOUT)
    encoding = getattr(sys.stdout, 'encoding', None) or 'utf-8'
    # old python has bug in p.stdout, so the following little
    # hack is required.
    for stdout in iter(p.stdout.readline, ''):
        if len(stdout) == 0:
            break
        # translate non unicode to unicode
        stdout = force_unicode(stdout, encoding)
        # StringIO store unicode
        b.write(stdout)
        # stdout require non unicode
        sys.stdout.write(from_unicode(stdout, encoding))
        sys.stdout.flush()
    buf = b.getvalue()
    p.stdout.close()
    return p.returncode or 0, buf
        


src/n/o/notify-0.2.0/src/notify/notifier.py   notify(Download)
import datetime
from notify.compat import keyring
from notify.executor import call
from notify.executor import get_command_str
from notify.mailer import create_message
    stdtime = datetime.datetime.now()
    # call subprocess
    exit_code, output = call(args)
    # calculate delta
    cdelta = time.clock() - stctime