Put only the stdout of the last shell command in a Python variable [duplicate]
问题 This question already has answers here : How to get the last N lines of a subprocess' stderr stream output? (2 answers) Closed 16 days ago . prova.sh contains: #!/bin/bash echo "Output that I don't want." echo "Output that I don't want." echo "Output that I don't want." echo -e "Output that I want.\nI want this too.\ \nI want this too." #This is the last command of the bash script, which is what I'm looking for. This solution: import subprocess output = subprocess.check_output('./prova.sh',