最初我運行此代碼時沒有使用前導"cmd"
,我收到拒絕訪問消息。 Postgres由一個無法登錄的帳戶作爲服務運行,我是一名運行此應用程序的管理員。包含"cmd"
的嘗試不會返回任何輸入。我的問題是如何執行這些語句來實現結果文件和數據更改?通過Java運行調用postgres命令Runtime.getruntime.exec()
String[] psqlCommands = {"cmd ",postgresLocation, " -dDatabase ", " -UUser ",
"-c ", "UPDATE host.user SET service = 1 WHERE service = 1;" +
"UPDATE host.permission SET service = 1 WHERE service = 2"};
Runtime.getRuntime().exec(psqlCommands);
String[] pgDumpCommands = {"cmd ", postgresLocation, " --data-only ",
"-t host.user_info -t host.permission -t host.group -t host.account -t host.password " +
"-UUser Database> "
+ DATA + "\\dataExport.sql"};
Runtime.getRuntime().exec(pgDumpCommands);
所生成的異常是一個例外Access Denied
即在Postgres_Bin
目錄。一旦我獲得必要的材料,我會發佈一個跟蹤。
Exception in thread "main" java.io.IOException: Cannot run program "d:\program f iles\postgres\bin": CreateProcess error=5, Access is denied
at java.lang.ProcessBuilder.start(Unknown Source) at java.lang.Runtime.exec(Unknown Source)
at java.lang.Runtime.exec(Unknown Source)
at Thing.main(Thing.java:85)
Caused by: java.io.IOException: CreateProcess error=5, Access is denied
at java.lang.ProcessImpl.create(Native Method)
at java.lang.ProcessImpl.<init>(Unknown Source)
at java.lang.ProcessImpl.start(Unknown Source)
... 4 more
CMD,你可以發佈你有 – 2010-12-07 13:28:46
一些異常或錯誤消息,這是訪問被拒絕,我將突出顯示在我的崗位 – Woot4Moo 2010-12-07 13:29:23