(command)
return out_text
Executes Linux shell commands
Executes Linux shell commands
Executes Linux shell commands
def shell_exec(command):
    """Executes Linux shell commands"""
    # Split the command into a list as needed by subprocess
    command = command.split()

    # Get both stdout and stderror from command. Grab the Python exception
    # if there is one.
    try:
        out_bytes = subprocess.check_output(command,
                                            stderr=subprocess.STDOUT)
    except subprocess.CalledProcessError as error:
        out_bytes = error.output
    except OSError as error:
        print('Could not run the following OS command. Sorry!\n'
              '   Command: {}'.format(command))
        print(error)
        sys.exit()

    # Return the lot as a text string for processing.
    out_text = out_bytes.decode('utf-8')
    out_text = out_text.rstrip()
    return out_text
def shell_exec ( command ) : # Split the command into a list as needed by subprocess command = command . split ( ) # Get both stdout and stderror from command. Grab the Python exception # if there is one. try : out_bytes = subprocess . check_output ( command , stderr = subprocess . STDOUT ) except subprocess . CalledProcessError as error : out_bytes = error . output except OSError as error : print ( 'Could not run the following OS command. Sorry!\n' '   Command: {}' . format ( command ) ) print ( error ) sys . exit ( ) # Return the lot as a text string for processing. out_text = out_bytes . decode ( 'utf-8' ) out_text = out_text . rstrip ( ) return out_text