Los scripts de Bash son notablemente útiles en el uso del sistema GNU/Linux y deseo saber cómo se pueden ejecutar dentro de las líneas de código de un programa escrito en Python.
Agradezco la ayuda por adelantado.

Código: Seleccionar todo
import os
micomando="elscript argumento1 argumento2 ..."
os.system(micomando)
Código: Seleccionar todo
def run_script(script, stdin=None):
"""Returns (stdout, stderr), raises error on non-zero return code"""
import subprocess
# Note: by using a list here (['bash', ...]) you avoid quoting issues, as the
# arguments are passed in exactly this order (spaces, quotes, and newlines won't
# cause problems):
proc = subprocess.Popen(['bash', '-c', script],
stdout=subprocess.PIPE, stderr=subprocess.PIPE,
stdin=subprocess.PIPE)
stdout, stderr = proc.communicate()
if proc.returncode:
raise ScriptException(proc.returncode, stdout, stderr, script)
return stdout, stderr
class ScriptException(Exception):
def __init__(self, returncode, stdout, stderr, script):
self.returncode = returncode
self.stdout = stdout
self.stderr = stderr
Exception.__init__('Error in script')