I am trying to write a python script that does a few things:
Open a terminal, cd's to a directory, and run's a command there.
Open a second terminal, cd's to another directory, and executes a file there.
The execution of step 1 can only be completed after step 2 has been completed. Step 1 and 2 should both be done from a python (or another language) script.
I tries using subprocess.Popen, subprocess.call, os.sytem, but this does not seem to work.
Does anyone have an idea how to do this?
The code I have so far:
import subprocess
terminal1 = subprocess.Popen(["gnome-terminal",'cd ~',"torcs -r ~/quickrace.xml"])
terminal2 = subprocess.Popen(['gnome-terminal','cd ~'])
-
Show us the code!Goralight– Goralight2017年11月21日 12:01:28 +00:00Commented Nov 21, 2017 at 12:01
-
1What do you mean by "does not seem to work"? What happens actually? And yes, please also post the code you've tried.CristiFati– CristiFati2017年11月21日 12:03:16 +00:00Commented Nov 21, 2017 at 12:03
-
1Why do you need a terminal?W.Mann– W.Mann2017年11月21日 12:05:09 +00:00Commented Nov 21, 2017 at 12:05
-
2I'm still not sure why you would need a terminal for that. Does the user have to interact somehow with the terminal?W.Mann– W.Mann2017年11月21日 12:09:17 +00:00Commented Nov 21, 2017 at 12:09
-
1stackoverflow.com/questions/4633738/…Matts– Matts2017年11月21日 12:10:11 +00:00Commented Nov 21, 2017 at 12:10
1 Answer 1
I don't know if it's exactly what you want but try it, replace the $variables by what you want and i think it will run.
#!/bin/bash
xterm -e "pwd ; cd $PATH ; your command ; echo press RETURN to close this window ; read" # delete the echo and the read to don't stop the process and make it run quickly
xterm -e "pwd ; cd $OTHERPATH ; your command ; echo press RETURN to close this window ; read"
And think to install xterm if you don't have. (rpm -i xterm if you have rpm packages)
In python i made this but it's not exactly what you want, but it's a beginning i think.
# -*- coding: utf-8 -*-
import os
if __name__ == "__main__":
os.system('xterm -e "pwd ; cd $PATH ; your command ; echo press RETURN to close this window ; read" &') # delete the echo and the read to don't stop the process and make it run quickly
input("Press Enter to continue...")
os.system('xterm -e "pwd ; cd $OTHERPATH ; your command ; echo press RETURN to close this window ; read" &')