Skip to content Skip to sidebar Skip to footer

How To Open A Bash Session With Python And Keep Communicating With It?

I would like to open a bash session in python and keep interacting with it as if it was a terminal. This is what I have so far: import subprocess as s class Session: proc =

Solution 1:

Alright, full disclaimer, python may have been my first language, but sure ain't my best

This should get you started:

self.execute("/bin/bash")#spawnabashsession

After that, you can pipe commands to bash. I'm not fully sure what you're trying to achieve, but you can pipe using the docs here: https://docs.python.org/2/library/subprocess.html#subprocess.check_call

A quick experiment to prove this works: Go to your bash terminal Execute

echo"echo test" | /bin/bash

and the result?

test

NOT

echotest

Post a Comment for "How To Open A Bash Session With Python And Keep Communicating With It?"