1e7a88fd1SGeorge Keishingimport subprocess
2e7a88fd1SGeorge Keishing
3e7a88fd1SGeorge Keishing
4e7a88fd1SGeorge Keishingdef execute_cmd(parms_string, quiet=False):
5e7a88fd1SGeorge Keishing    r"""
6e7a88fd1SGeorge Keishing    Run CLI standard tool or scripts.
7e7a88fd1SGeorge Keishing
8e7a88fd1SGeorge Keishing    Description of variable:
9e7a88fd1SGeorge Keishing    parms_string         Command to execute from the current SHELL.
10e7a88fd1SGeorge Keishing    quiet                do not print tool error message if True
11e7a88fd1SGeorge Keishing    """
12e7a88fd1SGeorge Keishing
13*20f38712SPatrick Williams    result = subprocess.run(
14*20f38712SPatrick Williams        [parms_string],
15e7a88fd1SGeorge Keishing        stdout=subprocess.PIPE,
16e7a88fd1SGeorge Keishing        stderr=subprocess.PIPE,
17e7a88fd1SGeorge Keishing        shell=True,
18*20f38712SPatrick Williams        universal_newlines=True,
19*20f38712SPatrick Williams    )
20e7a88fd1SGeorge Keishing
21e7a88fd1SGeorge Keishing    if result.stderr and not quiet:
22*20f38712SPatrick Williams        print("\n\t\tERROR with %s " % parms_string)
23*20f38712SPatrick Williams        print("\t\t" + result.stderr)
24e7a88fd1SGeorge Keishing
25e7a88fd1SGeorge Keishing    return result.stdout
26