From: Brian Candler Date: 2009-02-25T22:05:26+09:00 Subject: Re: Can Ruby interact with the shell sh ? Raimon Fs wrote: > But he was referring using a pipe if the program was *other* than the > shell, and I want to interact with the shell. IO.popen in principle should work with any external program, including a shell. IO.popen("/bin/sh","r+") do |s| s.puts "ls /tmp; exit" puts s.read end require 'expect' to get a more convenient API for searching for responses. However you need to be careful to ensure you don't deadlock, either because the shell is trying to send you a large amount of data but you're not reading it, or because you're waiting for a particular string which doesn't appear. You also won't get any prompts in a non-interactive shell. You could try /bin/sh -i, but that may cause more problems if the shell expects to be connected to a pty. I have a vague idea that there's a spawn/pty library out there, which you can google for. That would be safest for commands which chat interactively. -- Posted via http://www.ruby-forum.com/.