简体   繁体   English

从Java调用pg_dump时命令行参数过多

[英]Too many command-line arguments when calling pg_dump from java

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. 在遇到问题后,我使用Java中的字符串以Postgres的字符串形式执行一些查询后,我开始使用字符串数组,这解决了我现有的问题。

After the switch I am now having an issue with pg_dump , but not with pg_restore . 切换之后,我现在遇到了pg_dump的问题,但是没有遇到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") pg_dump:命令行参数过多(第一个是“ data / completedDb.dump”)

ProcessBuilder produces the following for my execution: ProcessBuilder产生以下内容供我执行:

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 : 我正在使用Eclipse在Postgres数据库上的Java中通过Eclipse运行此操作:

 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. 我尝试使用Process.start()但遇到了相同的错误,所以我对自己做错的事情完全傻眼了。

Prior to this change, pg_dump was being executed properly as a single string. 在进行此更改之前, pg_dump已作为单个字符串正确执行。 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. 我不想回到那种方法,因为我想保持一致性,但是我也想弄清楚我在做什么错。

You should use -f before the output file name, since by default pg_dump outputs to stdout. 您应该在输出文件名之前使用-f,因为默认情况下pg_dump输出到stdout。

Try 尝试

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM