我知道有很多关于执行从java.But我无法使用提供的答案来解决我的问题解决过程中的问题。 我试图去创建Java应用程序的PostgreSQL数据库备份。 我用下面的代码
//ProcessBuilder probuilder = new ProcessBuilder(new String[]{"cmd","/c","D:/PostgreSQL 8.2/bin/pg_dump.exe","-U","usr","-i","-h","localhost","-p","5432","-F","c","-b","-f","D:/backup test/backups/test_27-1-2013_210.backup", "test"});
//ProcessBuilder probuilder = new ProcessBuilder(new String[]{"cmd","/c","D:\\PostgreSQL 8.2\\bin\\pg_dump.exe","-U","usr","-i","-h","localhost","-p","5432","-F","c","-b","-f","D:\\backup test\\backups\\test_27-1-2013_210.backup", "test"});
ProcessBuilder probuilder = new ProcessBuilder(new String[]{"cmd","/c","\"D:\\PostgreSQL 8.2\\bin\\pg_dump.exe\"","-U","usr","-i","-h","localhost","-p","5432","-F","c","-b","-f","\"D:\\backup test\\backups\\test_27-1-2013_210.backup\"", "test"});
Map<String, String> env = probuilder.environment();
env.put("PGPASSWORD", "mypass");
final Process process = probuilder.start();
上面的代码执行后我得到以下错误: D:\PostgreSQL' is not recognized as an internal or external command, operable program or batch file.
当路径备份文件包含空格,否则创建备份问题只occures。 我曾尝试同时使用斜线和反斜线在文件的路径和我引用文件的路径,但我每次都遇到了同样的错误。 命令可以从命令提示来执行。
我做错了。 有没有关于在的ProcessBuilder空格的参数个数一定的局限性。 谢谢