7
I need to create a script in Phyton that when executed is via mouse click or keyboard 'enter', it opens the linux terminal itself and execute any command inside it. I have already managed to get him to execute the command, but as long as the script is executed inside the terminal.
I tried everything I could via google, tried using.system(), subprocess(), but none solved. My code at this point is this:
#!/usr/bin/env python3
# -*- coding; utf-8 -*-
import subprocess
processo = subprocess.Popen(args = ['pantheon-terminal'],
stdin = subprocess.PIPE,
stderr = subprocess.PIPE,
shell = True)
processo.communicate('ls') # Aqui um erro
It should open the terminal and execute the ls command, but only open the terminal.
Edit: As you can see above, I was using process.communicate('ls'), that is, I was passing the command wrong way, but I still don’t know where to put the command to run inside the terminal that was opened by the script.