从java调用pg_dump时,命令行参数太多 [英] Too many command-line arguments when calling pg_dump from java
问题描述
在使用Java for postgres执行某些查询作为字符串的问题之后,我使用了字符串数组,这解决了我现有的问题。
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.
切换后我我现在遇到 pg_dump
的问题,但不是 pg_restore
。
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]
我收到以下错误:
pg_dump:命令行参数太多(首先是
data / completedDb.dump)
pg_dump: too many command-line arguments (first is "data/completedDb.dump")
ProcessBuilder为我的执行生成以下内容:
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
我正在运行这个通过eclipse,在postgres数据库中的Java,使用:
I'm running this through eclipse, in Java on a postgres database, using :
Runtime.getRuntime().exec();
我尝试过使用 Process.start()
但是得到了同样的错误,所以我对我做错了完全傻了。
I've tried using Process.start()
but got the same errors, so I'm totally dumbfounded at what I'm doing wrong.
在此更改之前, pg_dump
正在作为单个字符串正确执行。我不想回到那个方法,因为我想保持一致性,但我也想知道我在这里做错了什么。
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.
推荐答案
你应该在输出文件名之前使用-f,因为默认情况下pg_dump输出到stdout。
You should use -f before the output file name, since by default pg_dump outputs to stdout.
试试
[时间,./pg_dump,-U,lehigh,-d,lehigh,-Fc,-f,data / completedDb.dump]
[time, ./pg_dump, -U, lehigh, -d, lehigh, -Fc, -f, data/completedDb.dump]
这篇关于从java调用pg_dump时,命令行参数太多的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!