I want to execute multiple shell commands one after another. The commands are received from a remote device through socket. What i need to do is to create a shell that is accessible remotely. With subprocess.Popen
i am able to execute commands and get output. But if i want to execute cd MyDIR
and then ls -l
. If I execute it as 2 lines of code, i get file listing of the parent directory rather than the the directory i cd into. Using cd MyDIR && ls -l
gives the required result. If i use the communicate method, i am not getting any result and also the stdin gets closed. Can someone help me with a piece of code?
Edit
The solution given here Interacting with bash from python doesn't solve my problem as i want to keep the shell active as long as possible and as much as needed. Trying the solution on that pages gives a message that IO operation on closed file.