From: Raimon Fs Date: 2009-02-26T03:04:27+09:00 Subject: Re: Can Ruby interact with the shell sh ? See, this is what I was referring to when I said a program other than > the shell. You're using the shell here, but you almost certainly don't > need to be. The program whose output you actually care about if not > /bin/sh, but /usr/local/bin/vpnclient > > So, you could change your code in this way: > > IO.popen("/usr/local/bin/vpnclient connect xxxxx user xxxxxxx pwd > xxxxxxxxxx","r+") do |s| > > while line = s.gets do > puts " ** #{line}" > if line =~ %r{y/n} > s.puts 'y' > end > end > > end > > > I don't have the vpnclient program on my machine, so I can't test it, > but it should work exactly the same. Or, if my code is not exactly > correct, I hope at least I've conveyed the idea clearly. > > Incidentally, there is a command line tool called 'yes' that will help > you accomplish what you want as well. > > system("yes | /usr/local/bin/vpnclient connect xxxxx user xxxxxxx pwd > xxxxxxxxxx") > > Of course, that only helps with the immediate situation where the only > interactivity is answering y/n questions and you want to answer all of > them 'y', but it where you can use it, it's a lot simpler. thanks a lot for all this usefull information, I think the 'yes' command is the top winner today :-) regards, r. ps. I can't test the code now as the VPN has been blocked today -- Posted via http://www.ruby-forum.com/.