Java运行时vacuumdb

时间:2016-04-21 05:08:54

标签: java processbuilder

我试图从java运行时运行真空数据库。我在命令工具中运行的语法相同但它可以运行但是从java运行它并不是:

final String cmd = "vacuumdb, -d wsemp0408, -v, -z;";

    try {
        System.out.println("ABC BACKUP START");
        java.lang.Runtime rt = java.lang.Runtime.getRuntime();
        java.lang.Process p = rt.exec(cmd);
        System.out.println("ABC BACKUP END");
    }

出现此错误:

java.io.IOException: Cannot run program "vacuumdb,": java.io.IOException: error=2, No such file or directory
at java.lang.ProcessBuilder.start(ProcessBuilder.java:459)
at java.lang.Runtime.exec(Runtime.java:593)
at java.lang.Runtime.exec(Runtime.java:431)
at java.lang.Runtime.exec(Runtime.java:328)
at accelteam.sop.backup.DBBackup.start(DBBackup.java:35)
at accelteam.sop.Sop.run(Sop.java:20)
Caused by: java.io.IOException: java.io.IOException: error=2, No such file or directory
at java.lang.UNIXProcess.<init>(UNIXProcess.java:148)
at java.lang.ProcessImpl.start(ProcessImpl.java:65)
at java.lang.ProcessBuilder.start(ProcessBuilder.java:452)
... 5 more

之前有人遇到过这个吗?

添加完整路径仍显示错误:

java.io.IOException: Cannot run program "/usr/lib/postgresql/9.3/bin/vacuumdb,": java.io.IOException: error=2, No such file or directory

我创建了一个使用root和chmod 777的exe jar文件希望它的权限问题,但仍然是相同的

1 个答案:

答案 0 :(得分:0)

通过添加完整路径并删除,

来修复
final String cmd = "/usr/lib/postgresql/9.3/bin/vacuumdb -d wsemp0408 -v -z";

这样运行正确。