def run_script(script):
script = 'set -euo pipefail\n' + script
try:
with open(os.devnull) as devnull:
# is this the right way to block stdin?
data = subprocess.check_output(['bash', '-c', script], stderr=subprocess.STDOUT, stdin=devnull)
status = 0
except subprocess.CalledProcessError as ex:
data = ex.output
status = ex.returncode
data = data.decode('utf8')
if status != 0:
raise PheWebError(
'FAILED with status {}\n'.format(status) +
'output was:\n' +
data)
return data
评论列表
文章目录