Skip to content Skip to sidebar Skip to footer

How To Interact With A Terminal In Python

I'm working on a small script. The script should open 3 terminals and interact with this terminals independently. I am pretty understand that subprocess is the best way to do that

Solution 1:

You can run both commands concurrently without opening terminals.

importsubprocessprocess1= subprocess.Popen(["ls", "-l"])
process2 = subprocess.Popen(["ls", "-l"])

If you run that code you will see that the directory is listed twice, interleaved together. You can expand this for your specific needs:

tcprelay1 = subprocess.Popen(["tcprelay", "telnet"])
tcprelay2 = subprocess.Popen(["tcprelay", "--portoffset [arg1] [arg2]")

Post a Comment for "How To Interact With A Terminal In Python"