Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I've tried several different ways to get this to run, all unsuccessfully!

Currently, I have a groovy script that tries to execute the Postgresql (9.2) 'createdb' command like this:

def createDbCmdLine = "-p 5433 --encoding=UTF8 --template=template0 myDatabaseName"
ant.exec(executable:'fullpath/bin/createdb') {
    arg(line: "$createDbCmdLine")
    env(key:"PGPASSWORD", value:"myPassword")
}

However, this just hangs forever. When I tried creating a string and executing:

["sh", "-c", theStringHere].execute()

the result was the same - hangs forever. In this case though, I printed the string. When I ran that on the command line (directly or via 'sh -c') it worked perfectly - after the command completes, I can enter postgresql via 'psql' do a \l and see the database created.

Anyone know what the problem is?

share|improve this question

1 Answer 1

The most likely issue would be createdb not seeing the environment variable and hanging waiting for the password.

I think you have two options. The first is to continue the shell escapes and try to use a .pgpass file, but the other is to connect to the postgres (or other existing db) and create the database manually. To do this, issue the following SQL:

 CREATE DATABASE myDatabaseName WITH TEMPLATE template0 ENCODING utf8;
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.