# Copyright (c) 2017-2018 Weitian LI <wt@liwt.net>
# MIT license

import os
import subprocess
import shutil


def setup_pfiles(tools):
    """
    Copy the parameter files of the specified tools to the current
    working directory, and setup the ``PFILES`` environment variable.
    By perferring the local copy of parameter files, the conflicts
    when running multiple instance of the same CIAO tools can be avoided.

    Parameters
    ----------
    tools : list[str]
        Name list of the tools to be set up
    """
    for tool in tools:
        pfile = subprocess.check_output([
            "paccess", tool
        ]).decode("utf-8").strip()
        subprocess.check_call(["punlearn", tool])
        try:
            shutil.copy(pfile, ".")
        except shutil.SameFileError:
            pass

    # Update the ``PFILES`` environment variable to prefer the local copy
    os.environ["PFILES"] = "./:" + os.environ["PFILES"]

@@ -101,16 +101,973 @@
  shutil%0A
+import logging%0A%0A%0Alogger = logging.getLogger(__name__)%0A%0A%0Adef run_command(tool, args, capture_stdout=True, check=True):%0A    %22%22%22%0A    Clear and then run the CIAO tool with the arguments.%0A%0A    Parameters%0A    ----------%0A    tool : str%0A        Name of the CIAO tool.%0A    args : list%5Bstr%5D%0A        List of arguments for the tool.%0A    capture_stdout : bool%0A        Capture the standard output of the command and return.%0A    check : bool%0A        Do not ignore the command failure if %60%60check=True%60%60.%0A%0A    Returns%0A    -------%0A    stdout : str%0A        Decoded standard output of the command if %60%60capture_stdout=True%60%60.%0A    %22%22%22%0A    subprocess.run(%5B'punlearn', tool%5D, check=check)%0A    cmd = %5Btool%5D + args%0A    logger.info('Run command: %25s' %25 ' '.join(cmd))%0A    stdout = subprocess.PIPE if capture_stdout else None%0A    p = subprocess.run(cmd, check=check, stdout=stdout)%0A    try:%0A        return p.stdout.decode('utf-8').strip()%0A    except AttributeError:%0A        return None%0A
 %0A%0Adef se

Add run_command() function