Sam Roberts
1/28/2005 11:20:00 PM
Wrote Dominik Werder <dwerder@gmx.net>, on Sat, Jan 29, 2005 at 12:40:52AM +0900:
> Hello!
>
> I tried to use the command line gnu privacy guard with ruby.
>
> The first attempt works quite good, using the Open3 lib:
>
> i,o,e=Open3.popen3 "gpg --batch -ea"
> i.puts ciphertext
> i.close
> o.each do |s|
> puts "Out: " << s
> end
> e.each do |s|
> puts "Err: " << s
> end
> o.close
> e.close
>
>
> But if I want language independant error codes then I have to pass gpg
> some file descriptor numbers like:
> gpg --no-tty --command-fd 14 --status-fd 15 --logger-fd 16
>
>
> My question is: How do I create such pipes?
>
> I already tried IO.pipe but gpg seems to not like them..
I just know how to do this in C, not ruby, but if no one has better
information, maybe these suggestions will help.
What did you do?
read, write = IO.pipe
if you do
cmd = File.popen("cmd --read-from #{read.fileno}")
and then do
read.close
write.print(..)
This didn't work?
Another approach would be to create the pipes, call Process.fork, parent
closes the read pipes, child closes the write pipes, then try and write
from parent to child (which are both still ruby).
If that works, have the child Kernel#exec gpg.
It works for me:
#!/usr/bin/ruby -w
r, w = IO.pipe
Kernel.fork do
# child
w.close
# you would do an exec, here.
puts "rd from #{r.fileno}"
puts "rd -> #{r.readline}"
exit 0
end
# parent
r.close
puts "wr on #{w.fileno}"
w.write("hello, chile\n")
Process.wait
exit 0
--
Sam Roberts <sroberts@certicom.com>