Too many command-line arguments when calling pg_dump from java

亡梦爱人 提交于 2019-12-07 21:18:31

问题


After running into an issue on executing some queries as strings in Java for postgres, I went using string arrays, which solved my existing issues.

After the switch I am now having an issue with pg_dump, but not with pg_restore.

When I supply my method with the following array:

[time, ./pg_dump, -U, lehigh, -d, lehigh, -Fc, data/completedDb.dump]

I get the following error:

pg_dump: too many command-line arguments (first is "data/completedDb.dump")

ProcessBuilder produces the following for my execution:

time ./pg_dump -U lehigh -d lehigh -Fc data/completedDb.dump

And it works fine when I add the output arrow, and remove the data folder, on the command line.

time ./pg_dump -U lehigh -d lehigh -Fc > completedDb.dump

I'm running this through eclipse, in Java on a postgres database, using :

 Runtime.getRuntime().exec();

I've tried using Process.start() but got the same errors, so I'm totally dumbfounded at what I'm doing wrong.

Prior to this change, pg_dump was being executed properly as a single string. I don't want to go back to that method as I want to maintain consistency, but I also want to figure out what I'm doing wrong here.


回答1:


You should use -f before the output file name, since by default pg_dump outputs to stdout.

Try

[time, ./pg_dump, -U, lehigh, -d, lehigh, -Fc, -f, data/completedDb.dump]



来源:https://stackoverflow.com/questions/34560868/too-many-command-line-arguments-when-calling-pg-dump-from-java

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!