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', shell=True, text=True)
print(output, end='')
puts the stdout of all shell commands in a variable:
Output that I don't want.
Output that I don't want.
Output that I don't want.
Output that I want.
I want this too.
I want this too.
but I just want the stdout of the last shell command:
Output that I want.
I want this too.
I want this too.
How can I get this?
Python 3.8.5
Existing questions only address how to get N lines or similar. In contrast, I only want the output of last command.