I am attempting to write a very simple rake task (and merge it into a rather large rake task) that will call the following command and pass in a randomly generated password. For the moment, let s even fake the random generation and just give it a set password of test :
createuser -SDPRE test
The code I have for my task is as follows:
desc "Create a test user with test password"
task "test" do
puts( Creating User )
IO.popen "createuser -SDRPE test", w+ do |io|
io.write "test
test
"
io.close_write
end
raise createuser failed unless $?.success?
end
The io.write
appears not to work as I still have to enter the password. It s also not being clobbered. After running the task and entering the password manually, I can use that password to log in with psql
.
I have tried quite a few variations such as io.close
, opening the file as w
and even r
or r+
because I saw other examples that use it.
I am a bit stumped on how to get this to work. Any ideas/comments/answers would be greatly appreciated!
Edit 1: This is on a Debian (Lenny) Linux system in case it makes any difference.