opening shell using subprocess

Opening a shell can be useful in some cases. For instance, imagine that you are on a different network and you would like to use sockets to control another computer. All you need to do is open up a pipe to a shell, with the input being read with socket.revc() and the the output going to socket.write(text). In such a way, it becomes like a telnet or ssh session, whereas it’s like you are sitting directly on the machine. I thought that using the module subprocess in python would be ideal for it. However, whenever I used Popen to open a shell, I couldn’t keep write on stdin and get stdout only once, and then I would get a ‘Broken Pipe Error’. After a long search on comp.lang.python, I finally discovered that I need to set up the file descriptors to be non-blocking in order for the connection not to close when there is no more data to be written to stdin. What happens is that once the pipe detects that there is no more data to be read from stdin, the pipe issues a EOF and the pipe closes. Here is a link to the discussion on a forum: click

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s


%d bloggers like this: