popen’ing part 2
I guess I should rtfm before blogging about something. This is my new IO.popen block which allows you to run a process which wants input, like the adt (Adobe Debug Tool) package task (which asks for your certificate password):
IO.popen(@cmd) do |f| while s = f.read(1) printf s STDOUT.flush end end @process = $?
View the airake/runner.rb. The IO.read call if not given args will block until EOF. This means we can’t output anything until the process ends which makes it appear hung if its asking for input. The waitpid call in the previous version just picks up the Process::Status since the read was the blocking call, but you can get that from $? after the popen block returns. I needed to add the STDOUT flush since printf isn’t guaranteed to (and wasn’t) outputing on the adt password input since I think it waits for a newline. Also this totally works on windows, although the whole read char + printf + flush makes it feel like a typewriter. This might be solved by using the IO.read_nonblock method. I’ll need to look into that.
Also, I updated the blog css, which I was told was depressing. Now its a total ripoff of coudal.com instead of danwebb.net