Hello,
I've seen this problem many places, that is to say the problem with programmatically making backups from PostgreSQL. My solution is to use ExpectJ, but I'm having trouble getting my code to work.
I have the following code:
public class BackupUtility
{
public static void main(String[] args)
{
try
{
ExpectJ exp = new ExpectJ(20);
Spawn shell = exp.spawn("\"C:\\Program Files\\PostgreSQL\\8.4\\bin\\pg_dump.exe\" " +
"-h localhost -U myUserName myDB");
shell.expect("Password: ");
shell.send("myPassword");
System.out.println(shell.getCurrentStandardOutContents());
shell.expectClose()
}
catch (Exception e)
{
e.printStackTrace();
}
}
}
However, on the shell.expect line, it's timing out.
When I run this command from the command prompt, it looks like the following:
C:\Documents and Settings\bobjonesthe3rd>"C:\Program Files\PostgreSQL\8.4\bin\pg_dump" -h localhost -U myUserName myDB
Password:
So, I know it prompts for a password, but ExpectJ isn't receiving the prompt for some reason.
Any help would be much appreciated.
Thanks, Matt