E
E
enabl32018-02-05 14:01:04
Python
enabl3, 2018-02-05 14:01:04

How to run bash script from python?

Hello.
Please tell me how to properly run the bash script that is on the computer through the telegram bot, which is written in python and get a response from it?
If you run the script itself through python, it works, but it crashes through the bot, I can’t figure out how to properly organize the output of the result.
In a normal python script, I did this:

import subprocess
subprocess.call("test.sh")

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
Saboteur, 2018-02-05
@enabl3

proc = subprocess.Popen('./test.sh', stdout=subprocess.PIPE)
output = proc.stdout.read()
print output

P
Psq, 2018-02-05
@Psq

subprocess.call(['./test.sh'])

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question