Raimon Fs wrote:
Thanks to all,
It’s working now …
I’m aware of the dead-lock or unknow things, I’m experimenting with it.
This is because I have to upload some files to an ftp server, but I must
do it trgough a VPN connection.
I want to start this VPN connection manually, and once connected, fire
all the file upload.
Thanks, I’m sure I’ll have lots of new questions, but now I can go
further …
thanks again!
regards,
r.
IO.popen("/bin/sh",“r+”) do |s|
s.puts “/usr/local/bin/vpnclient connect xxxxxx user xxxxxx pwd
xxxxxxxx\n”
while line = s.gets do
puts " ** #{line}"
if line =~ %r{y/n}
s.puts ‘y’
end
end
end
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.