Hy,
I try to dump a postgresql database from my java application.
In cmd it goes ok:
pg_dump -U user database>outfile.sql
and CMD prompts for password
To access this command line from my java:
Runtime.getRuntime().exec("pg_dump -U user database>outfile.sql");
and now it waits for password.
I tried with Runtime.getRuntime().exec(String[])...
but nothing.
Somehow, I must set the parameter 'password' in .exec()
method,
pg_dump statement does not accept password in it's command line..
thanks Max,
I tried this
Process p = Runtime.getRuntime().exec(cmd);
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(p.getOutputStream()));
bw.write("password");
//bw.eriteLine();
bw.flush();
but still nothing. I used InputStreamReader to see errors or messages from cmd execution, and nothig. It still waits for 'Password'.
But I had another solution :
Process p = Runtime.getRuntime().exec("cmd /c start cmd.exe /C\"pg_dump -U user -W db>outfile.sql\"");
so the black prompter opens with 'Password:'. write the password, hit enter and it goes off.
that's enough for me.
Thanks
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With